1
+ import 'package:example/generated/translations.dart' ;
2
+ import 'package:flutter/material.dart' ;
3
+ import 'package:flutter_easyrefresh/easy_refresh.dart' ;
4
+
5
+ /// CustomScrollView示例页面
6
+ class SliverPage extends StatefulWidget {
7
+ @override
8
+ _SliverPageState createState () => _SliverPageState ();
9
+ }
10
+
11
+ class _SliverPageState extends State <SliverPage > {
12
+
13
+ List <String > addStr= ["1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" ,"8" ,"9" ,"0" ];
14
+ List <String > str= ["1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" ,"8" ,"9" ,"0" ];
15
+ GlobalKey <EasyRefreshState > _easyRefreshKey = new GlobalKey <EasyRefreshState >();
16
+ GlobalKey <RefreshHeaderState > _headerKey = new GlobalKey <RefreshHeaderState >();
17
+ GlobalKey <RefreshFooterState > _footerKey = new GlobalKey <RefreshFooterState >();
18
+
19
+ @override
20
+ Widget build (BuildContext context) {
21
+ return Scaffold (
22
+ body: new EasyRefresh (
23
+ key: _easyRefreshKey,
24
+ refreshHeader: ClassicsHeader (
25
+ key: _headerKey,
26
+ refreshText: Translations .of (context).text ("pullToRefresh" ),
27
+ refreshReadyText: Translations .of (context).text ("releaseToRefresh" ),
28
+ refreshingText: Translations .of (context).text ("refreshing" ) + "..." ,
29
+ refreshedText: Translations .of (context).text ("refreshed" ),
30
+ moreInfo: Translations .of (context).text ("updateAt" ),
31
+ bgColor: Colors .orange,
32
+ textColor: Colors .black,
33
+ ),
34
+ refreshFooter: ClassicsFooter (
35
+ key: _footerKey,
36
+ loadHeight: 50.0 ,
37
+ loadText: Translations .of (context).text ("pushToLoad" ),
38
+ loadReadyText: Translations .of (context).text ("releaseToLoad" ),
39
+ loadingText: Translations .of (context).text ("loading" ),
40
+ loadedText: Translations .of (context).text ("loaded" ),
41
+ noMoreText: Translations .of (context).text ("noMore" ),
42
+ moreInfo: Translations .of (context).text ("updateAt" ),
43
+ bgColor: Colors .orange,
44
+ textColor: Colors .black,
45
+ ),
46
+ onRefresh: () async {
47
+ await new Future .delayed (const Duration (seconds: 1 ), () {
48
+ setState (() {
49
+ str.clear ();
50
+ str.addAll (addStr);
51
+ });
52
+ });
53
+ },
54
+ loadMore: () async {
55
+ await new Future .delayed (const Duration (seconds: 1 ), () {
56
+ if (str.length < 20 ) {
57
+ setState (() {
58
+ str.addAll (addStr);
59
+ });
60
+ }
61
+ });
62
+ },
63
+ child: CustomScrollView (
64
+ // 手动维护semanticChildCount,用于判断是否没有更多数据
65
+ semanticChildCount: str.length,
66
+ slivers: < Widget > [
67
+ SliverAppBar (
68
+ floating: false ,
69
+ pinned: true ,
70
+ expandedHeight: 180.0 ,
71
+ flexibleSpace: FlexibleSpaceBar (
72
+ title: Text ("CustomScrollView" ),
73
+ ),
74
+ ),
75
+ SliverPadding (
76
+ padding: EdgeInsets .all (0.0 ),
77
+ sliver: SliverFixedExtentList (
78
+ itemExtent: 70.0 ,
79
+ delegate: SliverChildBuilderDelegate ((context, index){
80
+ return new Container (
81
+ height: 70.0 ,
82
+ child: Card (
83
+ child: new Center (
84
+ child: new Text (str[index],style: new TextStyle (fontSize: 18.0 ),),
85
+ ),
86
+ )
87
+ );
88
+ },
89
+ childCount: str.length,
90
+ )
91
+ ),
92
+ )
93
+ ],
94
+ )
95
+ )
96
+ );
97
+ }
98
+ }
0 commit comments