LCOV - code coverage report
Current view: top level - lib - liquid_swipe.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 41 44 93.2 %
Date: 2021-03-10 21:05:26 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/material.dart';
       2             : import 'package:flutter/widgets.dart';
       3             : import 'package:liquid_swipe/Helpers/Helpers.dart';
       4             : import 'package:liquid_swipe/PageHelpers/LiquidController.dart';
       5             : import 'package:liquid_swipe/PageHelpers/page_dragger.dart';
       6             : import 'package:liquid_swipe/PageHelpers/page_reveal.dart';
       7             : import 'package:liquid_swipe/Provider/LiquidProvider.dart';
       8             : import 'package:provider/provider.dart';
       9             : 
      10             : export 'package:liquid_swipe/Helpers/Helpers.dart';
      11             : export 'package:liquid_swipe/PageHelpers/LiquidController.dart';
      12             : 
      13           0 : final key = new GlobalKey<_LiquidSwipe>();
      14             : 
      15             : /// Callback to provide the current page Index whenever it changes
      16             : ///
      17             : /// Returns an [int] value.
      18             : ///
      19             : /// Simple Usage :
      20             : ///
      21             : /// Create your own method
      22             : ///
      23             : /// ```dart
      24             : /// pageChangeCallback(int page) {
      25             : ///   ...performActions
      26             : /// }
      27             : /// ```
      28             : /// add this methods as callback to [LiquidSwipe.onPageChangeCallback]
      29             : ///
      30             : /// ```dart
      31             : ///     LiquidSwipe(
      32             : ///       pages: pages,
      33             : ///       onPageChangeCallback: pageChangeCallback,
      34             : ///     ),
      35             : /// ```
      36             : ///
      37             : /// see also : [LiquidController.currentPage]
      38             : typedef OnPageChangeCallback = void Function(int activePageIndex);
      39             : 
      40             : /// Callback to provide the current UpdateType
      41             : ///
      42             : /// Returns an [UpdateType] value.
      43             : ///
      44             : /// Simple Usage :
      45             : ///
      46             : /// Create your own method
      47             : ///
      48             : /// ```dart
      49             : /// updateChangeCallback(UpdateType type) {
      50             : ///   ...performActions
      51             : /// }
      52             : /// ```
      53             : /// add this methods as callback to [LiquidSwipe.currentUpdateTypeCallback]
      54             : ///
      55             : /// ```dart
      56             : ///     LiquidSwipe(
      57             : ///       pages: pages,
      58             : ///       currentUpdateTypeCallback: updateChangeCallback,
      59             : ///     ),
      60             : /// ```
      61             : typedef CurrentUpdateTypeCallback = void Function(UpdateType updateType);
      62             : 
      63             : /// Callback to provide the slidePercentage, both vertical and horizontal
      64             : ///
      65             : /// Returns two [double] values.
      66             : ///
      67             : /// Simple Usage :
      68             : ///
      69             : /// use [LiquidSwipe.slidePercentCallback] for callbacks
      70             : ///
      71             : /// ```dart
      72             : ///     LiquidSwipe(
      73             : ///       pages: pages,
      74             : ///       slidePercentCallback: (slidePercentHorizontal, slidePercentVertical) => {
      75             : ///             ...performActions
      76             : ///       },
      77             : ///     ),
      78             : /// ```
      79             : typedef SlidePercentCallback = void Function(
      80             :     double slidePercentHorizontal, double slidePercentVertical);
      81             : 
      82             : /// LiquidSwipe widget for out of the box Animation between stacked Widgets.
      83             : ///
      84             : /// For Simple Usage LiquidSwipe just requires List of Widgets and assign it to [LiquidSwipe.pages]
      85             : ///
      86             : /// Pages can be or should be Containers or SizedBox etc. Please report if doesn't work on some specific type of the Widgets
      87             : ///
      88             : /// Example :
      89             : ///
      90             : /// ```dart
      91             : ///     LiquidSwipe(
      92             : ///       pages: pages,
      93             : ///     ),
      94             : /// ```
      95             : ///
      96             : /// All Other parameters are optional and can be neglected, otherwise see documentation related to each of them.
      97             : ///
      98             : /// An Example of LiquidSwipe with Default values (excluding callbacks) :
      99             : ///
     100             : /// ```dart
     101             : ///       LiquidSwipe(
     102             : ///           pages: pages,
     103             : ///           fullTransitionValue: FULL_TRANSITION_PX,
     104             : ///           initialPage: 0,
     105             : ///           enableSlideIcon: false,
     106             : ///           slideIconWidget: const Icon(Icons.arrow_back_ios),
     107             : ///           positionSlideIcon: 0.54,
     108             : ///           enableLoop: true,
     109             : ///           waveType: WaveType.liquidReveal,
     110             : ///           liquidController: liquidController,
     111             : ///           disableUserGesture: false,
     112             : ///           ignoreUserGestureWhileAnimating: false,
     113             : ///        ),
     114             : /// ```
     115             : class LiquidSwipe extends StatefulWidget {
     116             :   ///Required List of Widgets like Container/SizedBox
     117             :   ///
     118             :   /// sample page :
     119             :   ///
     120             :   /// ```dart
     121             :   ///     Container(
     122             :   ///      color: Colors.pink,
     123             :   ///      child: Column(
     124             :   ///       crossAxisAlignment: CrossAxisAlignment.center,
     125             :   ///       mainAxisSize: MainAxisSize.max,
     126             :   ///       mainAxisAlignment: MainAxisAlignment.spaceEvenly,
     127             :   ///       children: <Widget>[
     128             :   ///         Image.asset(
     129             :   ///           'assets/1.png',
     130             :   ///           fit: BoxFit.cover,
     131             :   ///         ),
     132             :   ///         Padding(
     133             :   ///           padding: EdgeInsets.all(20.0),
     134             :   ///         ),
     135             :   ///         Column(
     136             :   ///           children: <Widget>[
     137             :   ///             Text(
     138             :   ///               "Hi",
     139             :   ///               style: MyApp.style,
     140             :   ///             ),
     141             :   ///             Text(
     142             :   ///               "It's Me",
     143             :   ///               style: MyApp.style,
     144             :   ///             ),
     145             :   ///             Text(
     146             :   ///               "Sahdeep",
     147             :   ///               style: MyApp.style,
     148             :   ///             ),
     149             :   ///           ],
     150             :   ///         ),
     151             :   ///       ],
     152             :   ///     ),
     153             :   ///   ),
     154             :   /// ```
     155             :   ///
     156             :   /// You can just create a list using this type of widgets
     157             :   final List<Widget> pages;
     158             : 
     159             :   /// Required a double value for swipe animation sensitivity
     160             :   ///
     161             :   /// Default : 400
     162             :   ///
     163             :   /// Lower the value faster the animation
     164             :   ///
     165             :   /// 100 would make animation much faster than current
     166             :   final double fullTransitionValue;
     167             : 
     168             :   /// If you want to change the initial page
     169             :   ///
     170             :   /// Required a int value which should be greater than or equals to 0 and less then the pages length other wise exception will be thrown.
     171             :   final int initialPage;
     172             : 
     173             :   /// Required a Widget that will be visible only if [enableSlideIcon] is set to true
     174             :   ///
     175             :   /// If not provided and [enableSlideIcon] is set [true], `Icon(Icons.arrow_back_ios)` this will be used by default
     176             :   final Widget? slideIconWidget;
     177             : 
     178             :   /// Required a double value ranges from 0.0 - 1.0
     179             :   ///
     180             :   /// -1.0 represents the 0% of height of the canvas and 100% for 1.0, similarly 0.0 represents vertical centre
     181             :   final double positionSlideIcon;
     182             : 
     183             :   /// Required a bool value in order to make the swipe in loop mode or not, i.e., to repeat them or not after reaching last page.
     184             :   final bool enableLoop;
     185             : 
     186             :   ///Required a [LiquidController] object for some magic methods
     187             :   final LiquidController? liquidController;
     188             : 
     189             :   ///Type of Wave you want, its a enum, you might have to import helpers.dart
     190             :   final WaveType waveType;
     191             : 
     192             :   ///see [OnPageChangeCallback]
     193             :   final OnPageChangeCallback? onPageChangeCallback;
     194             : 
     195             :   ///see [CurrentUpdateTypeCallback]
     196             :   final CurrentUpdateTypeCallback? currentUpdateTypeCallback;
     197             : 
     198             :   ///see [SlidePercentCallback]
     199             :   final SlidePercentCallback? slidePercentCallback;
     200             : 
     201             :   ///Required a bool value for disabling Fast Animation between pages
     202             :   ///
     203             :   /// If true fast swiping is disabled
     204             :   final bool ignoreUserGestureWhileAnimating;
     205             : 
     206             :   ///Required a bool value for disabling the user touch. you can still perform programmatic swipes
     207             :   ///
     208             :   ///see also for runtime changes : [LiquidController.shouldDisableGestures]
     209             :   final bool disableUserGesture;
     210             : 
     211           1 :   const LiquidSwipe({
     212             :     Key? key,
     213             :     required this.pages,
     214             :     this.fullTransitionValue = FULL_TRANSITION_PX,
     215             :     this.initialPage = 0,
     216             :     this.slideIconWidget,
     217             :     this.positionSlideIcon = 0.8,
     218             :     this.enableLoop = true,
     219             :     this.liquidController,
     220             :     this.waveType = WaveType.liquidReveal,
     221             :     this.onPageChangeCallback,
     222             :     this.currentUpdateTypeCallback,
     223             :     this.slidePercentCallback,
     224             :     this.ignoreUserGestureWhileAnimating = false,
     225             :     this.disableUserGesture = false,
     226           3 :   })  : assert(initialPage >= 0 && initialPage < pages.length),
     227           2 :         assert(positionSlideIcon >= 0 && positionSlideIcon <= 1),
     228           1 :         super(key: key);
     229             : 
     230           1 :   @override
     231           1 :   State<StatefulWidget> createState() => _LiquidSwipe();
     232             : }
     233             : 
     234             : class _LiquidSwipe extends State<LiquidSwipe> with TickerProviderStateMixin {
     235             :   late LiquidController liquidController;
     236             : 
     237           1 :   @override
     238             :   void initState() {
     239           3 :     liquidController = widget.liquidController ?? LiquidController();
     240           1 :     super.initState();
     241             :   }
     242             : 
     243           1 :   @override
     244             :   Widget build(BuildContext context) {
     245           2 :     List<Widget> pages = widget.pages;
     246           1 :     return ChangeNotifierProvider<LiquidProvider>(
     247           1 :       create: (BuildContext context) {
     248           1 :         return LiquidProvider(
     249           2 :             initialPage: widget.initialPage,
     250           2 :             loop: widget.enableLoop,
     251           1 :             length: pages.length,
     252             :             vsync: this,
     253           2 :             slideIcon: widget.positionSlideIcon,
     254           2 :             currentUpdateTypeCallback: widget.currentUpdateTypeCallback,
     255           2 :             slidePercentCallback: widget.slidePercentCallback,
     256           2 :             onPageChangeCallback: widget.onPageChangeCallback,
     257           2 :             disableGesture: widget.disableUserGesture);
     258             :       },
     259           2 :       child: Consumer(builder: (BuildContext context, LiquidProvider model, _) {
     260           2 :         liquidController.setContext(context);
     261           1 :         return Stack(
     262             :           alignment: Alignment.center,
     263           1 :           children: <Widget>[
     264           2 :             model.slideDirection == SlideDirection.leftToRight
     265           0 :                 ? pages[model.activePageIndex]
     266           2 :                 : pages[model.nextPageIndex],
     267             :             //Pages
     268           1 :             PageReveal(
     269             :               //next page reveal
     270           1 :               horizontalReveal: model.slidePercentHor,
     271           2 :               child: model.slideDirection == SlideDirection.leftToRight
     272           0 :                   ? pages[model.nextPageIndex]
     273           2 :                   : pages[model.activePageIndex],
     274           1 :               slideDirection: model.slideDirection,
     275           1 :               iconSize: model.iconSize,
     276           2 :               waveType: widget.waveType,
     277           1 :               verticalReveal: model.slidePercentVer,
     278             :             ),
     279           1 :             PageDragger(
     280             :               //Used for gesture control
     281           2 :               fullTransitionPX: widget.fullTransitionValue,
     282           2 :               slideIconWidget: widget.slideIconWidget,
     283           2 :               iconPosition: widget.positionSlideIcon,
     284             :               ignoreUserGestureWhileAnimating:
     285           2 :                   widget.ignoreUserGestureWhileAnimating,
     286             :             ), //PageDragger
     287             :           ], //Widget//Stack
     288             :         );
     289             :       }),
     290             :     ); //Scaffold
     291             :   }
     292             : }

Generated by: LCOV version 1.15