LCOV - code coverage report
Current view: top level - src/ui/editor/widgets/progress_widget - progress_bar_widget.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 46 46 100.0 %
Date: 2020-12-04 18:41:24 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/material.dart';
       2             : import 'package:pal/src/ui/editor/widgets/progress_widget/pulsing_circle.dart';
       3             : 
       4             : import 'progress_bar.dart';
       5             : 
       6             : /* Controller class : Takes all the variables needed, and transformes them before rendering */
       7             : class ProgressBarWidget extends StatefulWidget {
       8             :   final double nbSteps;
       9             :   final ValueNotifier<int> step;
      10             : 
      11           4 :   const ProgressBarWidget({Key key, this.nbSteps, this.step}) : super(key: key);
      12             : 
      13           2 :   @override
      14           2 :   _ProgressBarWidgetState createState() => _ProgressBarWidgetState();
      15             : }
      16             : 
      17             : class _ProgressBarWidgetState extends State<ProgressBarWidget>
      18             :     with SingleTickerProviderStateMixin {
      19             :   // CORE ATTRIBUTES
      20             :   AnimationController controller;
      21             :   Animation animation;
      22             : 
      23             :   // STATE ATTRIBUTES
      24             :   double prevStep;
      25             : 
      26             :   // STEPS VARIABLES
      27             :   double _stepScale;
      28             : 
      29           2 :   @override
      30             :   void initState() {
      31             :     // SETUP
      32             :     // LISTENING TO STEP CHANGES
      33           8 :     widget.step.addListener(this.refresh);
      34             :     // INITIALIZING STEP SIZE : Bringing them to a smaller scale from 0 to 1*
      35          10 :     this._stepScale = 1 / (widget.nbSteps - 1);
      36             : 
      37             :     // CONTROLLER AND ANIMATION INIT
      38           2 :     this.controller =
      39           4 :         AnimationController(vsync: this, duration: Duration(milliseconds: 500));
      40             :     // ANIMATES THE PROGRESS BAR FROM [STEP-1] TO [STEP]
      41           2 :     this.animation =
      42          12 :         Tween<double>(begin: 0, end: this._stepScale * widget.step.value)
      43           4 :             .animate(this.controller);
      44          10 :     this.prevStep = widget.step.value.toDouble();
      45             :     // ANIMATES
      46           4 :     this.controller.forward();
      47           2 :     super.initState();
      48             :   }
      49             : 
      50           1 :   void refresh() {
      51           2 :     this.controller.reset();
      52             :     // CREATES NEW ANIMATION FROM NEW VALUES
      53           2 :     this.animation = Tween<double>(
      54           3 :             begin: this._stepScale * this.prevStep,
      55           5 :             end: this._stepScale * widget.step.value)
      56           2 :         .animate(this.controller);
      57           5 :     this.prevStep = widget.step.value.toDouble();
      58           2 :     setState(() {
      59           2 :       this.controller.forward();
      60             :     });
      61             :   }
      62             : 
      63           2 :   @override
      64             :   void dispose() {
      65           4 :     this.controller.stop();
      66           4 :     this.controller.dispose();
      67           2 :     super.dispose();
      68             :   }
      69             : 
      70           2 :   @override
      71             :   Widget build(BuildContext context) {
      72           2 :     return SizedBox(
      73             :       height: 25,
      74             : 
      75             :       // PLACING PULSING CIRCLES ON-TOP THE PROGRESS BAR
      76           2 :       child: Stack(
      77           2 :         children: [
      78             :           // PROGRESS BAR
      79           2 :           Align(
      80             :             alignment: Alignment.center,
      81           2 :             child: AnimatedBuilder(
      82           2 :               animation: this.controller,
      83           4 :               builder: (context, child) => ProgressBarRender(
      84           4 :                 value: this.animation.value,
      85           2 :                 key: ValueKey("ProgressBar"),
      86             :               ),
      87             :             ),
      88             :           ),
      89             : 
      90             :           // PUSLING CIRCLES
      91           2 :           Align(
      92             :             alignment: Alignment.center,
      93           2 :             child: Row(
      94             :               mainAxisAlignment: MainAxisAlignment.spaceBetween,
      95             :               // CREATES AS MANY PUSLING CIRCLES AS THERE OF STEPS
      96           2 :               children: [
      97           8 :                 for (var i = 0; i < widget.nbSteps; i++)
      98             :                   // CONTAINER NEEDED TO CREATE AN ALLOCATED SPACE FOR CIRCLE TU PULSE WITHOUR MOVING OTHERS
      99           2 :                   Container(
     100             :                     width: 25,
     101           2 :                     child: PulsingCircleWidget(
     102           8 :                       active: i == widget.step.value,
     103           8 :                       done: i < widget.step.value,
     104           2 :                       key: ValueKey("PulsingCircle"),
     105             :                     ),
     106             :                   )
     107             :               ],
     108             :             ),
     109             :           )
     110             :         ],
     111             :       ),
     112             :     );
     113             :   }
     114             : }

Generated by: LCOV version 1.14