|
1 | 1 | part of custom_refresh_indicator;
|
2 | 2 |
|
3 |
| -typedef RefreshCallback = Future<void> Function(); |
| 3 | +typedef IndicatorBuilder = Widget Function( |
| 4 | + BuildContext context, |
| 5 | + Widget child, |
| 6 | + IndicatorController controller, |
| 7 | +); |
4 | 8 |
|
5 | 9 | class CustomRefreshIndicator extends StatefulWidget {
|
6 | 10 | static const armedFromValue = 1.0;
|
7 |
| - static const defaultExtentPercentageToArmed = 0.3; |
| 11 | + static const defaultExtentPercentageToArmed = 0.20; |
8 | 12 |
|
| 13 | + /// Duration of changing [IndicatorController] value from `<1.0` to `0.0`. |
| 14 | + /// When user stop dragging list before it become to armed [IndicatorState]. |
9 | 15 | final Duration dragingToIdleDuration;
|
| 16 | + |
| 17 | + /// Duration of changing [IndicatorController] value from `<=1.5` to `1.0`. |
| 18 | + /// Will start just before [onRefresh] function invocation. |
10 | 19 | final Duration armedToLoadingDuration;
|
| 20 | + |
| 21 | + /// Duration of changing [IndicatorController] value from `1.0` to `0.0` |
| 22 | + /// when [onRefresh] callback was completed. |
11 | 23 | final Duration loadingToIdleDuration;
|
| 24 | + |
| 25 | + /// Whether to display leading glow |
12 | 26 | final bool leadingGlowVisible;
|
| 27 | + |
| 28 | + /// Whether to display trailing glow |
13 | 29 | final bool trailingGlowVisible;
|
| 30 | + |
| 31 | + /// Number of pixels that user should drag to change [IndicatorState] from idle to armed. |
14 | 32 | final double offsetToArmed;
|
| 33 | + |
| 34 | + /// Value from 0.0 to 1.0 that describes the percentage of scroll container extent |
| 35 | + /// that user should drag to change [IndicatorState] from idle to armed. |
15 | 36 | final double extentPercentageToArmed;
|
| 37 | + |
| 38 | + /// Part of widget tree that contains scrollable element (like ListView). |
| 39 | + /// Scroll notifications from the first scrollable element will be used |
| 40 | + /// to calculate [IndicatorController] data. |
16 | 41 | final Widget child;
|
17 |
| - final ChildTransformBuilder builder; |
| 42 | + |
| 43 | + /// Function in wich custom refresh indicator should be implemented. |
| 44 | + /// |
| 45 | + /// IMPORTANT: |
| 46 | + /// IT IS NOT CALLED ON EVERY [IndicatorController] DATA CHANGE. |
| 47 | + /// |
| 48 | + /// TIP: |
| 49 | + /// To rebuild widget on every [IndicatorController] data change, consider |
| 50 | + /// using [IndicatorController] that is passed to this function as the third argument |
| 51 | + /// in combination with [AnimationBuilder]. |
| 52 | + final IndicatorBuilder builder; |
| 53 | + |
| 54 | + /// A function that's called when the user has dragged the refresh indicator |
| 55 | + /// far enough to demonstrate that they want the app to refresh. |
| 56 | + /// The returned [Future] must complete when the refresh operation is finished. |
18 | 57 | final RefreshCallback onRefresh;
|
| 58 | + |
| 59 | + /// Indicator controller keeps all thata related to refresh indicator. |
| 60 | + /// It extends [ChangeNotifier] so that it could be listen for changes. |
| 61 | + /// |
| 62 | + /// TIP: |
| 63 | + /// Consider using it in combination with [AnimationBuilder] as animation argument |
| 64 | + /// |
| 65 | + /// The indicator controller will be passed as the third argument to the [builder] method. |
| 66 | + /// |
| 67 | + /// To better understand this data, look at example app. |
19 | 68 | final IndicatorController controller;
|
20 | 69 |
|
21 | 70 | CustomRefreshIndicator({
|
@@ -53,7 +102,7 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
|
53 | 102 | AnimationController _animationController;
|
54 | 103 | IndicatorController _customRefreshIndicatorController;
|
55 | 104 |
|
56 |
| - /// Keeps current custom refresh indicator data |
| 105 | + /// Current [IndicatorController] |
57 | 106 | IndicatorController get controller => _customRefreshIndicatorController;
|
58 | 107 |
|
59 | 108 | static const double _kPositionLimit = 1.5;
|
|
0 commit comments