aboutsummaryrefslogtreecommitdiffstats
path: root/lib/presentation/screens/dashboard/widgets/dashboard_content.dart
blob: 74f0d2a21105cd1399284468a2c674c5608e384e (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
import 'dart:math';

import 'package:flutter_ics_homescreen/export.dart';

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

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

class DashBoardState extends ConsumerState<DashBoard>
    with SingleTickerProviderStateMixin {
  late AnimationController _animationController;
  late Animation<double> _animation;
  static bool _isAnimationPlayed = false;

  @override
  void initState() {
    super.initState();
    _animationController = AnimationController(
      duration: const Duration(milliseconds: 1800),
      vsync: this,
      value: _isAnimationPlayed ? 1.0 : 0.0,
    );

    _animation = CurvedAnimation(
      parent: _animationController,
      curve: Curves.easeIn,
    );

    // Start the animation on first build.
    if (!_isAnimationPlayed) {
      Future.delayed(const Duration(milliseconds: 500), () {
        _animationController.forward();
        _isAnimationPlayed = true;
      });
    }
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    Widget svgImage = Align(
      alignment: Alignment.bottomCenter,
      child: SvgPicture.asset(
        'assets/Car Illustration.svg',
        width: 625,
        height: 440,
        fit: BoxFit.fitHeight,
      ),
    );

    Widget fadeContent = FadeTransition(
        opacity: _animation,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            const Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              //mainAxisSize: MainAxisSize.max,
              children: [
                RPMProgressIndicator(),
                SpeedProgressIndicator(),
                FuelProgressIndicator(),
              ],
            ),
            GestureDetector(
                onTap: () {
                  Random random = Random();
                  int randomState = random.nextInt(4);
                  var hybridState = HybridState.values[randomState];
                  ref
                      .read(hybridtateProvider.notifier)
                      .setHybridState(hybridState);
                },
                child: const HybridModel()),
            const Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                TemperatureWidget(),
                RangeWidget(),
              ],
            ),
            const CarStatus(),
          ],
        ));

    return Stack(
      alignment: Alignment.center,
      children: [
        Positioned.fill(
          child: fadeContent,
        ),
        Positioned(
          bottom: 138,
          child: svgImage,
        ),
      ],
    );
  }
}