LCOV - code coverage report
Current view: top level - lib/PageHelpers - LiquidController.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 14 14 100.0 %
Date: 2021-04-02 00:29:34 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/material.dart';
       2             : import 'package:liquid_swipe/Provider/LiquidProvider.dart';
       3             : import 'package:liquid_swipe/liquid_swipe.dart';
       4             : import 'package:provider/provider.dart';
       5             : 
       6             : /// Added in v1.5.0
       7             : ///
       8             : /// A controller class similar to [PageController] but with Limited Capabilities for now.
       9             : /// Provides method for dynamic changes to the [LiquidSwipe]
      10             : ///
      11             : /// Simple Usage :
      12             : ///
      13             : /// Firstly make an Object of [LiquidController] and initialize it in `initState()`
      14             : ///
      15             : /// ```dart
      16             : ///    LiquidController liquidController;
      17             : ///
      18             : ///    @override
      19             : ///    void initState() {
      20             : ///    super.initState();
      21             : ///    liquidController = LiquidController();
      22             : ///    }
      23             : /// ```
      24             : ///
      25             : /// Now simply add it to [LiquidSwipe]'s Constructor
      26             : ///
      27             : /// ```dart
      28             : ///    LiquidSwipe(
      29             : ///         pages: pages,
      30             : ///         LiquidController: liquidController,
      31             : ///     ),
      32             : ///
      33             : /// ```
      34             : ///
      35             : /// Only Rules/Limitation to its Usage is For now you can't use any method in Liquid Controller before build method is being called in which [LiquidSwipe] is initialized
      36             : ///
      37             : /// So we have to use them after LiquidSwipe is Built
      38             : ///
      39             : ///
      40             : class LiquidController {
      41             :   ///Provider model calls (not listenable) just used for calling its internal methods
      42             :   LiquidProvider? _provider;
      43             : 
      44           1 :   LiquidController();
      45             : 
      46             :   ///Internal Method Should not be used.
      47           1 :   setContext(BuildContext context) {
      48           2 :     _provider = Provider.of<LiquidProvider>(context, listen: false);
      49             :   }
      50             : 
      51             :   ///Jump Directly to mentioned Page index but without Animation
      52             :   ///see also : [LiquidProvider.jumpToPage]
      53           1 :   jumpToPage({required int page}) {
      54           1 :     assert(_provider != null,
      55             :         "LiquidController not attached to any LiquidSwipe Widget.");
      56           2 :     _provider?.jumpToPage(page);
      57             :   }
      58             : 
      59             :   ///Animate to mentioned page within given [Duration]
      60             :   ///Remember the [duration] here is the total duration in which it will animate though all pages not the single page
      61           1 :   animateToPage({required int page, int duration = 600}) {
      62           1 :     assert(_provider != null,
      63             :         "LiquidController not attached to any LiquidSwipe Widget.");
      64           2 :     _provider?.animateToPage(page, duration);
      65             :   }
      66             : 
      67             :   ///Getter to get current Page
      68             :   ///see also : [OnPageChangeCallback]
      69           3 :   int get currentPage => _provider?.activePageIndex ?? 0;
      70             : 
      71             :   ///Use this method to disable gestures during runtime, like on certain pages using [OnPageChangeCallback]
      72             :   ///If you want to disable gestures from start use [LiquidSwipe.disableUserGesture]
      73           1 :   shouldDisableGestures({required bool disable}) {
      74           1 :     assert(_provider != null,
      75             :         "LiquidController not attached to any LiquidSwipe Widget.");
      76           2 :     _provider?.setUserGesture = disable;
      77             :   }
      78             : 
      79             :   ///If somehow you want to check if gestures are disabled or not
      80             :   ///Returns [bool]
      81           3 :   bool get isUserGestureDisabled => _provider?.isUserGestureDisabled ?? false;
      82             : }

Generated by: LCOV version 1.15