|
| 1 | +import 'dart:async'; |
| 2 | + |
| 3 | +import 'package:example/generated/translations.dart'; |
| 4 | +import 'package:flutter/material.dart'; |
| 5 | +import 'package:flutter_easyrefresh/easy_refresh.dart'; |
| 6 | + |
| 7 | +/// 滚动条页面 |
| 8 | +class ScrollBarPage extends StatefulWidget { |
| 9 | + @override |
| 10 | + _ScrollBarPageState createState() => _ScrollBarPageState(); |
| 11 | +} |
| 12 | + |
| 13 | +class _ScrollBarPageState extends State<ScrollBarPage> { |
| 14 | + List<String> addStr = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]; |
| 15 | + List<String> str = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]; |
| 16 | + GlobalKey<EasyRefreshState> _easyRefreshKey = |
| 17 | + new GlobalKey<EasyRefreshState>(); |
| 18 | + GlobalKey<RefreshHeaderState> _headerKey = |
| 19 | + new GlobalKey<RefreshHeaderState>(); |
| 20 | + GlobalKey<RefreshFooterState> _footerKey = |
| 21 | + new GlobalKey<RefreshFooterState>(); |
| 22 | + |
| 23 | + @override |
| 24 | + Widget build(BuildContext context) { |
| 25 | + return Scaffold( |
| 26 | + appBar: AppBar( |
| 27 | + title: Text(Translations.of(context).text("scrollBar")), |
| 28 | + ), |
| 29 | + body: Center( |
| 30 | + child: new EasyRefresh( |
| 31 | + key: _easyRefreshKey, |
| 32 | + builder: (context, child, scrollController){ |
| 33 | + return Scrollbar(child: child); |
| 34 | + }, |
| 35 | + refreshHeader: ClassicsHeader( |
| 36 | + key: _headerKey, |
| 37 | + refreshText: Translations.of(context).text("pullToRefresh"), |
| 38 | + refreshReadyText: Translations.of(context).text("releaseToRefresh"), |
| 39 | + refreshingText: Translations.of(context).text("refreshing") + "...", |
| 40 | + refreshedText: Translations.of(context).text("refreshed"), |
| 41 | + moreInfo: Translations.of(context).text("updateAt"), |
| 42 | + bgColor: Colors.transparent, |
| 43 | + textColor: Colors.black87, |
| 44 | + moreInfoColor: Colors.black54, |
| 45 | + showMore: true, |
| 46 | + ), |
| 47 | + refreshFooter: ClassicsFooter( |
| 48 | + key: _footerKey, |
| 49 | + loadText: Translations.of(context).text("pushToLoad"), |
| 50 | + loadReadyText: Translations.of(context).text("releaseToLoad"), |
| 51 | + loadingText: Translations.of(context).text("loading"), |
| 52 | + loadedText: Translations.of(context).text("loaded"), |
| 53 | + noMoreText: Translations.of(context).text("noMore"), |
| 54 | + moreInfo: Translations.of(context).text("updateAt"), |
| 55 | + bgColor: Colors.transparent, |
| 56 | + textColor: Colors.black87, |
| 57 | + moreInfoColor: Colors.black54, |
| 58 | + showMore: true, |
| 59 | + ), |
| 60 | + child: new ListView.builder( |
| 61 | + //ListView的Item |
| 62 | + itemCount: str.length, |
| 63 | + itemBuilder: (BuildContext context, int index) { |
| 64 | + return new Container( |
| 65 | + height: 70.0, |
| 66 | + child: Card( |
| 67 | + child: new Center( |
| 68 | + child: new Text( |
| 69 | + str[index], |
| 70 | + style: new TextStyle(fontSize: 18.0), |
| 71 | + ), |
| 72 | + ), |
| 73 | + )); |
| 74 | + }), |
| 75 | + onRefresh: () async { |
| 76 | + await new Future.delayed(const Duration(seconds: 1), () { |
| 77 | + setState(() { |
| 78 | + str.clear(); |
| 79 | + str.addAll(addStr); |
| 80 | + }); |
| 81 | + }); |
| 82 | + }, |
| 83 | + loadMore: () async { |
| 84 | + await new Future.delayed(const Duration(seconds: 1), () { |
| 85 | + if (str.length < 20) { |
| 86 | + setState(() { |
| 87 | + str.addAll(addStr); |
| 88 | + }); |
| 89 | + } |
| 90 | + }); |
| 91 | + }, |
| 92 | + )), |
| 93 | + ); |
| 94 | + } |
| 95 | +} |
0 commit comments