@@ -16,11 +16,13 @@ class CustomRefreshIndicator extends StatefulWidget {
1616 final Widget child;
1717 final ChildTransformBuilder builder;
1818 final RefreshCallback onRefresh;
19+ final IndicatorController controller;
1920
2021 CustomRefreshIndicator ({
2122 @required this .child,
2223 @required this .onRefresh,
2324 @required this .builder,
25+ this .controller,
2426 this .offsetToArmed,
2527 this .extentPercentageToArmed = defaultExtentPercentageToArmed,
2628 this .dragingToIdleDuration = const Duration (milliseconds: 300 ),
@@ -37,16 +39,22 @@ class CustomRefreshIndicator extends StatefulWidget {
3739
3840class _CustomRefreshIndicatorState extends State <CustomRefreshIndicator >
3941 with TickerProviderStateMixin {
42+ bool __canStart = false ;
43+
4044 /// Whether custom refresh indicator can change [IndicatorState] from `idle` to `draging`
41- bool _canStart = false ;
45+ bool get _canStart =>
46+ __canStart && _customRefreshIndicatorController._refreshEnabled;
47+ set _canStart (bool canStart) {
48+ __canStart = canStart;
49+ }
4250
4351 double _dragOffset;
4452
4553 AnimationController _animationController;
46- IndicatorController _customRefreshIndicatorData ;
54+ IndicatorController _customRefreshIndicatorController ;
4755
48- /// Current custom refresh indicator data
49- IndicatorController get controller => _customRefreshIndicatorData ;
56+ /// Keeps current custom refresh indicator data
57+ IndicatorController get controller => _customRefreshIndicatorController ;
5058
5159 static const double _kPositionLimit = 1.5 ;
5260 static const double _kInitialValue = 0.0 ;
@@ -56,32 +64,30 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
5664 _dragOffset = 0 ;
5765 _canStart = false ;
5866
59- _customRefreshIndicatorData = IndicatorController (
60- value: _kInitialValue,
61- );
67+ _customRefreshIndicatorController =
68+ widget.controller ?? IndicatorController ._();
6269
6370 _animationController = AnimationController (
6471 vsync: this ,
6572 upperBound: _kPositionLimit,
66- lowerBound: 0.0 ,
67- )
68- ..addListener (_updateCustomRefreshIndicatorData)
69- ..value = _kInitialValue;
73+ lowerBound: _kInitialValue,
74+ value: _kInitialValue,
75+ )..addListener (_updateCustomRefreshIndicatorValue);
7076
7177 super .initState ();
7278 }
7379
7480 @override
7581 void dispose () {
7682 _animationController.dispose ();
77- _customRefreshIndicatorData .dispose ();
83+ _customRefreshIndicatorController .dispose ();
7884 super .dispose ();
7985 }
8086
8187 /// Notifies the listeners of the controller
82- void _updateCustomRefreshIndicatorData () {
83- _customRefreshIndicatorData. updateAndNotify (
84- value : _animationController? .value ?? _kInitialValue,
88+ void _updateCustomRefreshIndicatorValue () {
89+ _customRefreshIndicatorController. _setValue (
90+ _animationController? .value ?? _kInitialValue,
8591 );
8692 }
8793
@@ -219,9 +225,6 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
219225 controller._setIndicatorState (IndicatorState .idle);
220226 }
221227
222- static final ChildTransformBuilder noChildTransform =
223- (context, child, data) => child;
224-
225228 @override
226229 Widget build (BuildContext context) => widget.builder.call (
227230 context,
0 commit comments