@@ -121,10 +121,12 @@ class RefreshIndicator extends StatefulWidget {
121
121
final RefreshIndicatorLocation location;
122
122
123
123
@override
124
- _RefreshIndicatorState createState () => new _RefreshIndicatorState ();
124
+ RefreshIndicatorState createState () => new RefreshIndicatorState ();
125
125
}
126
126
127
- class _RefreshIndicatorState extends State <RefreshIndicator > {
127
+ /// Contains the state for a [RefreshIndicator] . This class can be used to
128
+ /// programmatically show the refresh indicator, see the [show] method.
129
+ class RefreshIndicatorState extends State <RefreshIndicator > {
128
130
final AnimationController _sizeController = new AnimationController ();
129
131
final AnimationController _scaleController = new AnimationController ();
130
132
Animation <double > _sizeFactor;
@@ -280,36 +282,56 @@ class _RefreshIndicatorState extends State<RefreshIndicator> {
280
282
}
281
283
}
282
284
283
- Future <Null > _doHandlePointerUp ( PointerUpEvent event ) async {
284
- if ( _mode == _RefreshIndicatorMode .armed) {
285
- _mode = _RefreshIndicatorMode .snap ;
286
- await _sizeController. animateTo ( 1.0 / _kDragSizeFactorLimit, duration : _kIndicatorSnapDuration);
287
- if (mounted && _mode == _RefreshIndicatorMode .snap) {
288
- setState (() {
289
- _mode = _RefreshIndicatorMode .refresh; // Show the indeterminate progress indicator.
290
- });
285
+ Future <Null > _show ( ) async {
286
+ _mode = _RefreshIndicatorMode .snap;
287
+ await _sizeController. animateTo ( 1.0 / _kDragSizeFactorLimit, duration : _kIndicatorSnapDuration) ;
288
+ if (mounted && _mode == _RefreshIndicatorMode .snap) {
289
+ assert (config.refresh != null );
290
+ setState (() {
291
+ _mode = _RefreshIndicatorMode .refresh; // Show the indeterminate progress indicator.
292
+ });
291
293
292
- // Only one refresh callback is allowed to run at a time. If the user
293
- // attempts to start a refresh while one is still running ("pending") we
294
- // just continue to wait on the pending refresh.
295
- if (_pendingRefreshFuture == null )
296
- _pendingRefreshFuture = config.refresh ();
297
- await _pendingRefreshFuture;
298
- bool completed = _pendingRefreshFuture != null ;
299
- _pendingRefreshFuture = null ;
300
-
301
- if (mounted && completed && _mode == _RefreshIndicatorMode .refresh)
302
- _dismiss (_DismissTransition .slide);
303
- }
304
- } else if (_mode == _RefreshIndicatorMode .drag) {
305
- _dismiss (_DismissTransition .shrink);
294
+ // Only one refresh callback is allowed to run at a time. If the user
295
+ // attempts to start a refresh while one is still running ("pending") we
296
+ // just continue to wait on the pending refresh.
297
+ if (_pendingRefreshFuture == null )
298
+ _pendingRefreshFuture = config.refresh ();
299
+ await _pendingRefreshFuture;
300
+ bool completed = _pendingRefreshFuture != null ;
301
+ _pendingRefreshFuture = null ;
302
+
303
+ if (mounted && completed && _mode == _RefreshIndicatorMode .refresh)
304
+ _dismiss (_DismissTransition .slide);
306
305
}
307
306
}
308
307
308
+ Future <Null > _doHandlePointerUp (PointerUpEvent event) async {
309
+ if (_mode == _RefreshIndicatorMode .armed)
310
+ _show ();
311
+ else if (_mode == _RefreshIndicatorMode .drag)
312
+ _dismiss (_DismissTransition .shrink);
313
+ }
314
+
309
315
void _handlePointerUp (PointerEvent event) {
310
316
_doHandlePointerUp (event);
311
317
}
312
318
319
+ /// Show the refresh indicator and run the refresh callback as if it had
320
+ /// been started interactively. If this method is called while the refresh
321
+ /// callback is running, it quietly does nothing.
322
+ ///
323
+ /// See also:
324
+ ///
325
+ /// * [GlobalKey] (creating the RefreshIndicator with a [GlobalKey<RefreshIndicatorState>]
326
+ /// will make it possible to refer to the [RefreshIndicatorState] later)
327
+ Future <Null > show () async {
328
+ if (_mode != _RefreshIndicatorMode .refresh) {
329
+ _sizeController.value = 0.0 ;
330
+ _scaleController.value = 0.0 ;
331
+ await _show ();
332
+ }
333
+ }
334
+
313
335
@override
314
336
Widget build (BuildContext context) {
315
337
final bool showIndeterminateIndicator =
0 commit comments