aboutsummaryrefslogtreecommitdiffstats
path: root/lib/presentation/screens/splash/widget/splash_content.dart
blob: 325baeb6900b160304c0cb790c08af0deaf7e402 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import 'package:flutter_ics_homescreen/export.dart';

class SplashContent extends ConsumerStatefulWidget {
  const SplashContent({super.key});

  @override
  SplashContentState createState() => SplashContentState();
}

class SplashContentState extends ConsumerState<SplashContent>
    with TickerProviderStateMixin {
  late Animation<double> _fadeAnimation;
  late AnimationController _lottieController;
  late AnimationController _fadeController;
  bool _showLottieAnimation =
      true; // New state to control the visibility of Lottie animation

  @override
  void initState() {
    super.initState();
    // If you need to control the Lottie animation, initialize its controller
    _lottieController = AnimationController(
      vsync: this,
      duration: const Duration(seconds: 7),
    );

    Future.delayed(const Duration(milliseconds: 1500), () {
      _lottieController.repeat();
    });

    // Initialize the fade animation controller
    _fadeController = AnimationController(
      vsync: this,
      duration: const Duration(seconds: 1), // Fade transition duration
    );

    // Set up the fade animation
    _fadeAnimation =
        Tween<double>(begin: 0.0, end: 1.0).animate(_fadeController)
          ..addListener(() {
            // Check the status of the animation and set the state to hide Lottie when fading starts.
            if (_fadeAnimation.value > 0.0 && _showLottieAnimation) {
              setState(() {
                _showLottieAnimation = false;
              });
            }
          });

    // Start the fade-in transition after the Lottie animation has played for some time
    Future.delayed(const Duration(seconds: 6), () {
      // Stop the Lottie animation if needed
      _lottieController.stop();

      // Start the fade-in transition
      _fadeController.forward();
    });
  }

  @override
  void dispose() {
    // Dispose the animation controller to release resources.
    _fadeController.dispose();
    _lottieController.dispose();
    super.dispose();
  }

  @override
  void didChangeDependencies() {
    ref.read(vehicleProvider.notifier).startListen();
    super.didChangeDependencies();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        if (_showLottieAnimation)
          Center(
            child: Lottie.asset(
              'animations/Logo_JSON.json',
              controller: _lottieController,
              onLoaded: (composition) {
                _lottieController.duration = composition.duration;
              },
            ),
          ),
        // FadeTransition wraps existing UI.
        FadeTransition(
          opacity: _fadeAnimation,
          child: Center(
            child: buildWarningUI(),
          ),
        ),
      ],
    );
  }

  Widget buildWarningUI() {
    return Column(
      children: [
        const Expanded(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'WARNING:',
                style: TextStyle(color: Color(0xFFC1D8FF), fontSize: 44),
              ),
              SizedBox(height: 38),
              SizedBox(
                //color: Colors.amber,
                width: 757,
                height: 488,
                child: Text(
                  splashWarning,
                  style: TextStyle(color: Colors.white, fontSize: 40, height: 1.7, fontWeight: FontWeight.w400),
                  textAlign: TextAlign.left,

                ),
              ),
            ],
          ),
        ),
        GenericButton(
          heigth: 122,
          width: 452,
          text: 'Continue',
          onTap: () {
            ref.read(vehicleProvider.notifier).setInitialState();
            ref
                .read(appProvider.notifier)
                .update((state) => state = AppState.dashboard);
          },
        ),
       
        const SizedBox(
          height: 72,
        )
      ],
    );
  }
}