RefreshIndicatorState.show() (#4877)

This commit is contained in:
Hans Muller
2016-07-11 10:11:34 -07:00
committed by GitHub
parent 445f250c91
commit 12764a0066
2 changed files with 60 additions and 25 deletions

View File

@@ -18,6 +18,8 @@ class OverscrollDemo extends StatefulWidget {
}
class OverscrollDemoState extends State<OverscrollDemo> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = new GlobalKey<RefreshIndicatorState>();
static final GlobalKey<ScrollableState> _scrollableKey = new GlobalKey<ScrollableState>();
static final List<String> _items = <String>[
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'
@@ -28,10 +30,19 @@ class OverscrollDemoState extends State<OverscrollDemo> {
Future<Null> refresh() {
Completer<Null> completer = new Completer<Null>();
new Timer(new Duration(seconds: 3), () { completer.complete(null); });
return completer.future;
return completer.future.then((_) {
_scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text("Refresh complete"),
action: new SnackBarAction(
label: 'RETRY',
onPressed: () {
_refreshIndicatorKey.currentState.show();
}
)
));
});
}
@override
Widget build(BuildContext context) {
String indicatorTypeText;
@@ -68,6 +79,7 @@ class OverscrollDemoState extends State<OverscrollDemo> {
break;
case IndicatorType.refresh:
body = new RefreshIndicator(
key: _refreshIndicatorKey,
child: body,
refresh: refresh,
scrollableKey: _scrollableKey,
@@ -77,6 +89,7 @@ class OverscrollDemoState extends State<OverscrollDemo> {
}
return new Scaffold(
key: _scaffoldKey,
appBar: new AppBar(
title: new Text('$indicatorTypeText'),
actions: <Widget>[