LCOV - code coverage report
Current view: top level - lib/PageHelpers - animated_page_dragger.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 22 24 91.7 %
Date: 2021-03-10 21:05:26 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:ui';
       2             : 
       3             : import 'package:flutter/material.dart';
       4             : import 'package:liquid_swipe/Helpers/Helpers.dart';
       5             : import 'package:liquid_swipe/Helpers/slide_update.dart';
       6             : import 'package:liquid_swipe/Provider/LiquidProvider.dart';
       7             : 
       8             : /// Internal Class
       9             : ///
      10             : /// This class provides the animation controller
      11             : /// used when user stops dragging and page
      12             : /// reveal is not completed.
      13             : class AnimatedPageDragger {
      14             :   ///SlideDirection LTR, RTL or none
      15             :   final SlideDirection slideDirection;
      16             : 
      17             :   ///Current transition goal, either close the page or reveal it
      18             :   final TransitionGoal transitionGoal;
      19             : 
      20             :   ///Animation controller for Completing the Animation when user is Done with dragging
      21             :   late AnimationController completionAnimationController;
      22             : 
      23             :   ///Constructor
      24           1 :   AnimatedPageDragger({
      25             :     required this.slideDirection,
      26             :     required this.transitionGoal,
      27             :     required double slidePercentVer,
      28             :     required double slidePercentHor,
      29             :     required LiquidProvider slideUpdateStream,
      30             :     required TickerProvider vsync,
      31             :   }) {
      32             :     final startSlidePercentHor = slidePercentHor;
      33             :     final startSlidePercentVer = slidePercentVer;
      34             :     double? endSlidePercentHor, endSlidePercentVer;
      35             :     Duration duration;
      36             : 
      37             :     //We have to complete the page reveal
      38           2 :     if (transitionGoal == TransitionGoal.open) {
      39             :       endSlidePercentHor = 1.0;
      40             : 
      41           1 :       endSlidePercentVer = slideUpdateStream.positionSlideIcon;
      42             : 
      43           1 :       final slideRemaining = 1.0 - slidePercentHor;
      44             :       //Standard value take for drag velocity to avoid complex calculations.
      45           1 :       duration = Duration(
      46           2 :         milliseconds: (slideRemaining / PERCENT_PER_MILLISECOND).round(),
      47             :       );
      48             :     }
      49             :     //We have to close the page reveal
      50             :     else {
      51             :       endSlidePercentHor = endSlidePercentVer = 0.0;
      52             : 
      53           1 :       duration = Duration(
      54           2 :         milliseconds: (slidePercentHor / PERCENT_PER_MILLISECOND).round(),
      55             :       );
      56             :     }
      57             : 
      58             :     //Adding listener to animation controller
      59             :     //Also value to animation controller vary from 0.0 to 1.0 according to duration.
      60           2 :     completionAnimationController = AnimationController(
      61             :       duration: duration,
      62             :       vsync: vsync,
      63             :     )
      64           2 :       ..addListener(() {
      65           1 :         final slidePercent = lerpDouble(
      66             :           startSlidePercentHor,
      67             :           endSlidePercentHor,
      68           2 :           completionAnimationController.value,
      69             :         );
      70           1 :         final slidePercentVer = lerpDouble(
      71             :           startSlidePercentVer,
      72             :           endSlidePercentVer,
      73           2 :           completionAnimationController.value,
      74             :         );
      75             :         //Adding to slide update stream
      76           2 :         slideUpdateStream.updateSlide(SlideUpdate(
      77           1 :           slideDirection,
      78             :           slidePercent!,
      79             :           slidePercentVer!,
      80             :           UpdateType.animating,
      81             :         ));
      82             :       })
      83           2 :       ..addStatusListener((AnimationStatus status) {
      84             :         //When animation has done executing
      85           1 :         if (status == AnimationStatus.completed) {
      86             :           //Adding to slide update stream
      87           2 :           slideUpdateStream.updateSlide(SlideUpdate(
      88           1 :             slideDirection,
      89             :             slidePercentHor,
      90             :             slidePercentVer,
      91             :             UpdateType.doneAnimating,
      92             :           ));
      93             :         }
      94             :       });
      95             :   }
      96             : 
      97             :   ///This method is used to run animation Controller in forward
      98           1 :   void run() {
      99           2 :     completionAnimationController.forward(from: 0.0);
     100             :   }
     101             : 
     102             :   ///This method is used to dispose animation controller
     103           0 :   void dispose() {
     104           0 :     completionAnimationController.dispose();
     105             :   }
     106             : }

Generated by: LCOV version 1.15