/
link_header_example.dart
177 lines (161 loc) · 4.83 KB
/
link_header_example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* Author: Jpeng
* Email: peng8350@gmail.com
* Time: 2019-06-26 13:28
*/
/*
use to place indicator to other places,such as WeChat friend circle refresh effect
int 1.4.7 version will add it
*/
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import '../../Item.dart';
class LinkHeaderExample extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _LinkHeaderExampleState();
}
}
class _LinkHeaderExampleState extends State<LinkHeaderExample> {
RefreshController _refreshController = RefreshController();
final Key linkKey = GlobalKey();
List<String> data = ["1", "2", "3", "4", "5", "6", "7", "8", "9"];
final ScrollController _scrollController = ScrollController();
bool dismissAppbar = false;
@override
void initState() {
// TODO: implement initState
_scrollController.addListener(() {
final bool ifdismissAppbar = _scrollController.offset >= 136.0;
if (dismissAppbar != ifdismissAppbar) {
if (mounted) setState(() {});
}
dismissAppbar = ifdismissAppbar;
});
super.initState();
}
@override
void dispose() {
// TODO: implement dispose
_refreshController.dispose();
_scrollController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return RefreshConfiguration.copyAncestor(
context: context,
child: Scaffold(
body: Stack(
children: <Widget>[
Stack(
children: <Widget>[
Positioned(
top: -150.0,
bottom: 0.0,
left: 0.0,
right: 0.0,
child: SmartRefresher(
controller: _refreshController,
header: LinkHeader(linkKey: linkKey),
onRefresh: () async {
await Future.delayed(Duration(milliseconds: 3000));
_refreshController.refreshCompleted();
},
child: CustomScrollView(
controller: _scrollController,
slivers: <Widget>[
SliverToBoxAdapter(
child: Image.asset(
"images/qqbg.jpg",
fit: BoxFit.fill,
height: 300.0,
),
),
SliverFixedExtentList(
delegate: SliverChildBuilderDelegate(
(c, i) => Item(
title: data[i],
),
childCount: data.length),
itemExtent: 100.0,
)
],
),
),
)
],
),
Container(
height: 64.0,
child: AppBar(
backgroundColor:
dismissAppbar ? Colors.blueAccent : Colors.transparent,
elevation: dismissAppbar ? 1.0 : 0.0,
title: SimpleLinkBar(
key: linkKey,
),
),
)
],
),
),
maxOverScrollExtent: 100,
);
}
}
class SimpleLinkBar extends StatefulWidget {
SimpleLinkBar({Key key}) : super(key: key);
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _SimpleLinkBarState();
}
}
class _SimpleLinkBarState extends State<SimpleLinkBar>
with RefreshProcessor, SingleTickerProviderStateMixin {
RefreshStatus _status = RefreshStatus.idle;
AnimationController _animationController;
@override
void dispose() {
// TODO: implement dispose
super.dispose();
}
@override
void initState() {
// TODO: implement initState
_animationController = AnimationController(vsync: this);
super.initState();
}
@override
Future endRefresh() {
// TODO: implement endRefresh
_animationController.animateTo(0.0, duration: Duration(milliseconds: 300));
return Future.value();
}
@override
void onOffsetChange(double offset) {
// TODO: implement onOffsetChange
if (_status != RefreshStatus.refreshing)
_animationController.value = offset / 80.0;
super.onOffsetChange(offset);
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return ScaleTransition(
child: CupertinoActivityIndicator(),
scale: _animationController,
);
}
@override
void onModeChange(RefreshStatus mode) {
// TODO: implement onModeChange
super.onModeChange(mode);
_status = mode;
setState(() {});
}
}