@@ -27,7 +27,7 @@ class CustomRefreshIndicator extends StatefulWidget {
2727 final Duration loadingToIdleDuration;
2828
2929 /// {@macro custom_refresh_indicator.complete_state}
30- final Duration completeStateDuration;
30+ final Duration ? completeStateDuration;
3131
3232 /// A check that specifies whether a [ScrollNotification] should be
3333 /// handled by this widget.
@@ -43,11 +43,11 @@ class CustomRefreshIndicator extends StatefulWidget {
4343 final bool trailingGlowVisible;
4444
4545 /// Number of pixels that user should drag to change [IndicatorState] from idle to armed.
46- final double offsetToArmed;
46+ final double ? offsetToArmed;
4747
4848 /// Value from 0.0 to 1.0 that describes the percentage of scroll container extent
4949 /// that user should drag to change [IndicatorState] from idle to armed.
50- final double extentPercentageToArmed;
50+ final double ? extentPercentageToArmed;
5151
5252 /// Part of widget tree that contains scrollable element (like ListView).
5353 /// Scroll notifications from the first scrollable element will be used
@@ -79,13 +79,13 @@ class CustomRefreshIndicator extends StatefulWidget {
7979 /// The indicator controller will be passed as the third argument to the [builder] method.
8080 ///
8181 /// To better understand this data, look at example app.
82- final IndicatorController controller;
82+ final IndicatorController ? controller;
8383
8484 CustomRefreshIndicator ({
85- Key key,
86- @ required this .child,
87- @ required this .onRefresh,
88- @ required this .builder,
85+ Key ? key,
86+ required this .child,
87+ required this .onRefresh,
88+ required this .builder,
8989 this .notificationPredicate = defaultScrollNotificationPredicate,
9090 this .controller,
9191 this .offsetToArmed,
@@ -96,9 +96,7 @@ class CustomRefreshIndicator extends StatefulWidget {
9696 this .completeStateDuration,
9797 this .leadingGlowVisible = false ,
9898 this .trailingGlowVisible = true ,
99- }) : assert (child != null , '`child` argument cannot be null.' ),
100- assert (builder != null , '`builder` argument cannot be null.' ),
101- assert (
99+ }) : assert (
102100 extentPercentageToArmed == null || offsetToArmed == null ,
103101 'Providing `extentPercentageToArmed` argument take no effect when `offsetToArmed` is provided. '
104102 'Remove redundant argument.' ,
@@ -120,10 +118,10 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
120118 __canStart = canStart;
121119 }
122120
123- double _dragOffset;
121+ late double _dragOffset;
124122
125- AnimationController _animationController;
126- IndicatorController _customRefreshIndicatorController;
123+ late AnimationController _animationController;
124+ late IndicatorController _customRefreshIndicatorController;
127125
128126 /// Current [IndicatorController]
129127 IndicatorController get controller => _customRefreshIndicatorController;
@@ -157,11 +155,8 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
157155 }
158156
159157 /// Notifies the listeners of the controller
160- void _updateCustomRefreshIndicatorValue () {
161- _customRefreshIndicatorController._setValue (
162- _animationController? .value ?? _kInitialValue,
163- );
164- }
158+ void _updateCustomRefreshIndicatorValue () =>
159+ _customRefreshIndicatorController._setValue (_animationController.value);
165160
166161 bool _handleGlowNotification (OverscrollIndicatorNotification notification) {
167162 if (notification.depth != 0 ) return false ;
@@ -190,7 +185,7 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
190185 if (notification.metrics.extentBefore > 0.0 ) {
191186 _hide ();
192187 } else {
193- _dragOffset -= notification.scrollDelta;
188+ _dragOffset -= notification.scrollDelta! ;
194189 _calculateDragOffset (notification.metrics.viewportDimension);
195190 }
196191 if (controller.state == IndicatorState .armed &&
@@ -229,10 +224,12 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
229224
230225 double newValue;
231226
227+ final offsetToArmed = widget.offsetToArmed;
228+
232229 /// If [offestToArmed] is provided then it will be used otherwise
233230 /// [extentPercentageToArmed]
234- if (widget. offsetToArmed != null ) {
235- newValue = _dragOffset / widget. offsetToArmed;
231+ if (offsetToArmed != null ) {
232+ newValue = _dragOffset / offsetToArmed;
236233 } else {
237234 final extentPercentageToArmed = widget.extentPercentageToArmed ??
238235 CustomRefreshIndicator .defaultExtentPercentageToArmed;
@@ -281,9 +278,10 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
281278 if (! mounted) return ;
282279
283280 /// optional complete state
284- if (widget.completeStateDuration != null ) {
281+ final completeStateDuration = widget.completeStateDuration;
282+ if (completeStateDuration != null ) {
285283 controller._setIndicatorState (IndicatorState .complete);
286- await Future .delayed (widget. completeStateDuration);
284+ await Future .delayed (completeStateDuration);
287285 }
288286
289287 if (! mounted) return ;
0 commit comments