Refresh indicator (#3354)
This commit is contained in:
93
examples/material_gallery/lib/demo/overscroll_demo.dart
Normal file
93
examples/material_gallery/lib/demo/overscroll_demo.dart
Normal file
@@ -0,0 +1,93 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum IndicatorType { overscroll, refresh }
|
||||
|
||||
class OverscrollDemo extends StatefulWidget {
|
||||
OverscrollDemo({ Key key }) : super(key: key);
|
||||
|
||||
@override
|
||||
OverscrollDemoState createState() => new OverscrollDemoState();
|
||||
}
|
||||
|
||||
class OverscrollDemoState extends State<OverscrollDemo> {
|
||||
static final List<String> _items = <String>[
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'
|
||||
];
|
||||
|
||||
IndicatorType _type = IndicatorType.refresh;
|
||||
|
||||
Future<Null> refresh() {
|
||||
Completer<Null> completer = new Completer<Null>();
|
||||
new Timer(new Duration(seconds: 3), () { completer.complete(null); });
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String indicatorTypeText;
|
||||
switch(_type) {
|
||||
case IndicatorType.overscroll:
|
||||
indicatorTypeText = 'Over-scroll indicator';
|
||||
break;
|
||||
case IndicatorType.refresh:
|
||||
indicatorTypeText = 'Refresh indicator';
|
||||
break;
|
||||
}
|
||||
|
||||
Widget body = new MaterialList(
|
||||
type: MaterialListType.threeLine,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
children: _items.map((String item) {
|
||||
return new ListItem(
|
||||
isThreeLine: true,
|
||||
leading: new CircleAvatar(child: new Text(item)),
|
||||
title: new Text('This item represents $item.'),
|
||||
subtitle: new Text('Even more additional list item information appears on line three.')
|
||||
);
|
||||
})
|
||||
);
|
||||
switch(_type) {
|
||||
case IndicatorType.overscroll:
|
||||
body = new OverscrollIndicator(child: body);
|
||||
break;
|
||||
case IndicatorType.refresh:
|
||||
body = new RefreshIndicator(child: body, refresh: refresh);
|
||||
break;
|
||||
}
|
||||
|
||||
return new Scaffold(
|
||||
appBar: new AppBar(
|
||||
title: new Text('$indicatorTypeText'),
|
||||
actions: <Widget>[
|
||||
new IconButton(
|
||||
icon: Icons.refresh,
|
||||
tooltip: 'Pull to refresh',
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_type = IndicatorType.refresh;
|
||||
});
|
||||
}
|
||||
),
|
||||
new IconButton(
|
||||
icon: Icons.play_for_work,
|
||||
tooltip: 'Over-scroll indicator',
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_type = IndicatorType.overscroll;
|
||||
});
|
||||
}
|
||||
)
|
||||
]
|
||||
),
|
||||
body: body
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import '../demo/leave_behind_demo.dart';
|
||||
import '../demo/list_demo.dart';
|
||||
import '../demo/modal_bottom_sheet_demo.dart';
|
||||
import '../demo/menu_demo.dart';
|
||||
import '../demo/overscroll_demo.dart';
|
||||
import '../demo/page_selector_demo.dart';
|
||||
import '../demo/persistent_bottom_sheet_demo.dart';
|
||||
import '../demo/progress_indicator_demo.dart';
|
||||
@@ -133,6 +134,7 @@ class GalleryHomeState extends State<GalleryHome> {
|
||||
new GalleryItem(title: 'List', builder: () => new ListDemo()),
|
||||
new GalleryItem(title: 'Menus', builder: () => new MenuDemo()),
|
||||
new GalleryItem(title: 'Modal bottom sheet', builder: () => new ModalBottomSheetDemo()),
|
||||
new GalleryItem(title: 'Over-scroll', builder: () => new OverscrollDemo()),
|
||||
new GalleryItem(title: 'Page selector', builder: () => new PageSelectorDemo()),
|
||||
new GalleryItem(title: 'Persistent bottom sheet', builder: () => new PersistentBottomSheetDemo()),
|
||||
new GalleryItem(title: 'Progress indicators', builder: () => new ProgressIndicatorDemo()),
|
||||
|
||||
Reference in New Issue
Block a user