Skip to content

Commit 621181c

Browse files
committed
add animations for TrendPage
1 parent 2839067 commit 621181c

File tree

3 files changed

+81
-26
lines changed

3 files changed

+81
-26
lines changed

lib/page/trend/trend_page.dart

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'dart:async';
22

3+
import 'package:animations/animations.dart';
4+
import 'package:gsy_github_app_flutter/page/repos/repository_detail_page.dart';
35
import 'package:flutter/material.dart';
46
import 'package:flutter/rendering.dart';
57
import 'package:flutter_redux/flutter_redux.dart';
@@ -30,7 +32,10 @@ class TrendPage extends StatefulWidget {
3032
TrendPageState createState() => TrendPageState();
3133
}
3234

33-
class TrendPageState extends State<TrendPage> with AutomaticKeepAliveClientMixin<TrendPage>, SingleTickerProviderStateMixin {
35+
class TrendPageState extends State<TrendPage>
36+
with
37+
AutomaticKeepAliveClientMixin<TrendPage>,
38+
SingleTickerProviderStateMixin {
3439
///显示数据时间
3540
TrendTypeModel selectTime = null;
3641
int selectTimeIndex = 0;
@@ -40,7 +45,8 @@ class TrendPageState extends State<TrendPage> with AutomaticKeepAliveClientMixin
4045
int selectTypeIndex = 0;
4146

4247
/// NestedScrollView 的刷新状态 GlobalKey ,方便主动刷新使用
43-
final GlobalKey<NestedScrollViewRefreshIndicatorState> refreshIndicatorKey = new GlobalKey<NestedScrollViewRefreshIndicatorState>();
48+
final GlobalKey<NestedScrollViewRefreshIndicatorState> refreshIndicatorKey =
49+
new GlobalKey<NestedScrollViewRefreshIndicatorState>();
4450

4551
///滚动控制与监听
4652
final ScrollController scrollController = new ScrollController();
@@ -58,20 +64,34 @@ class TrendPageState extends State<TrendPage> with AutomaticKeepAliveClientMixin
5864

5965
scrollToTop() {
6066
if (scrollController.offset <= 0) {
61-
scrollController.animateTo(0, duration: Duration(milliseconds: 600), curve: Curves.linear).then((_) {
67+
scrollController
68+
.animateTo(0,
69+
duration: Duration(milliseconds: 600), curve: Curves.linear)
70+
.then((_) {
6271
_showRefreshLoading();
6372
});
6473
} else {
65-
scrollController.animateTo(0, duration: Duration(milliseconds: 600), curve: Curves.linear);
74+
scrollController.animateTo(0,
75+
duration: Duration(milliseconds: 600), curve: Curves.linear);
6676
}
6777
}
6878

6979
///绘制tiem
7080
_renderItem(e) {
7181
ReposViewModel reposViewModel = ReposViewModel.fromTrendMap(e);
72-
return new ReposItem(reposViewModel, onPressed: () {
73-
NavigatorUtils.goReposDetail(context, reposViewModel.ownerName, reposViewModel.repositoryName);
74-
});
82+
return OpenContainer(
83+
closedColor: Colors.transparent,
84+
closedElevation: 0,
85+
transitionType: ContainerTransitionType.fade,
86+
openBuilder: (BuildContext context, VoidCallback _) {
87+
return NavigatorUtils.pageContainer(RepositoryDetailPage(
88+
reposViewModel.ownerName, reposViewModel.repositoryName));
89+
},
90+
tappable: true,
91+
closedBuilder: (BuildContext _, VoidCallback openContainer) {
92+
return new ReposItem(reposViewModel, onPressed: null);
93+
},
94+
);
7595
}
7696

7797
///绘制头部可选item
@@ -88,34 +108,45 @@ class TrendPageState extends State<TrendPage> with AutomaticKeepAliveClientMixin
88108
borderRadius: BorderRadius.all(radius),
89109
),
90110
child: new Padding(
91-
padding: new EdgeInsets.only(left: 0.0, top: 5.0, right: 0.0, bottom: 5.0),
111+
padding:
112+
new EdgeInsets.only(left: 0.0, top: 5.0, right: 0.0, bottom: 5.0),
92113
child: new Row(
93114
children: <Widget>[
94-
_renderHeaderPopItem(selectTime.name, trendTimeList, (TrendTypeModel result) {
115+
_renderHeaderPopItem(selectTime.name, trendTimeList,
116+
(TrendTypeModel result) {
95117
if (trendBloc.isLoading) {
96-
Fluttertoast.showToast(msg: GSYLocalizations.i18n(context).loading_text);
118+
Fluttertoast.showToast(
119+
msg: GSYLocalizations.i18n(context).loading_text);
97120
return;
98121
}
99-
scrollController.animateTo(0, duration: Duration(milliseconds: 200), curve: Curves.bounceInOut).then((_) {
122+
scrollController
123+
.animateTo(0,
124+
duration: Duration(milliseconds: 200),
125+
curve: Curves.bounceInOut)
126+
.then((_) {
100127
setState(() {
101128
selectTime = result;
102129
selectTimeIndex = trendTimeList.indexOf(result);
103-
print("##### ${selectTimeIndex}");
104130
});
105131
_showRefreshLoading();
106132
});
107133
}),
108134
new Container(height: 10.0, width: 0.5, color: GSYColors.white),
109-
_renderHeaderPopItem(selectType.name, trendTypeList, (TrendTypeModel result) {
135+
_renderHeaderPopItem(selectType.name, trendTypeList,
136+
(TrendTypeModel result) {
110137
if (trendBloc.isLoading) {
111-
Fluttertoast.showToast(msg: GSYLocalizations.i18n(context).loading_text);
138+
Fluttertoast.showToast(
139+
msg: GSYLocalizations.i18n(context).loading_text);
112140
return;
113141
}
114-
scrollController.animateTo(0, duration: Duration(milliseconds: 200), curve: Curves.bounceInOut).then((_) {
142+
scrollController
143+
.animateTo(0,
144+
duration: Duration(milliseconds: 200),
145+
curve: Curves.bounceInOut)
146+
.then((_) {
115147
setState(() {
116148
selectType = result;
117149
selectTypeIndex = trendTypeList.indexOf(result);
118-
print("##### ${selectTimeIndex}");
119150
});
120151
_showRefreshLoading();
121152
});
@@ -127,10 +158,12 @@ class TrendPageState extends State<TrendPage> with AutomaticKeepAliveClientMixin
127158
}
128159

129160
///或者头部可选弹出item容器
130-
_renderHeaderPopItem(String data, List<TrendTypeModel> list, PopupMenuItemSelected<TrendTypeModel> onSelected) {
161+
_renderHeaderPopItem(String data, List<TrendTypeModel> list,
162+
PopupMenuItemSelected<TrendTypeModel> onSelected) {
131163
return new Expanded(
132164
child: new PopupMenuButton<TrendTypeModel>(
133-
child: new Center(child: new Text(data, style: GSYConstant.middleTextWhite)),
165+
child: new Center(
166+
child: new Text(data, style: GSYConstant.middleTextWhite)),
134167
onSelected: onSelected,
135168
itemBuilder: (BuildContext context) {
136169
return _renderHeaderPopItemChild(list);
@@ -180,9 +213,16 @@ class TrendPageState extends State<TrendPage> with AutomaticKeepAliveClientMixin
180213

181214
///空页面
182215
Widget _buildEmpty() {
183-
var statusBar = MediaQueryData.fromWindow(WidgetsBinding.instance.window).padding.top;
184-
var bottomArea = MediaQueryData.fromWindow(WidgetsBinding.instance.window).padding.bottom;
185-
var height = MediaQuery.of(context).size.height - statusBar - bottomArea - kBottomNavigationBarHeight - kToolbarHeight;
216+
var statusBar =
217+
MediaQueryData.fromWindow(WidgetsBinding.instance.window).padding.top;
218+
var bottomArea = MediaQueryData.fromWindow(WidgetsBinding.instance.window)
219+
.padding
220+
.bottom;
221+
var height = MediaQuery.of(context).size.height -
222+
statusBar -
223+
bottomArea -
224+
kBottomNavigationBarHeight -
225+
kToolbarHeight;
186226
return SingleChildScrollView(
187227
child: new Container(
188228
height: height,
@@ -192,10 +232,14 @@ class TrendPageState extends State<TrendPage> with AutomaticKeepAliveClientMixin
192232
children: <Widget>[
193233
FlatButton(
194234
onPressed: () {},
195-
child: new Image(image: new AssetImage(GSYICons.DEFAULT_USER_ICON), width: 70.0, height: 70.0),
235+
child: new Image(
236+
image: new AssetImage(GSYICons.DEFAULT_USER_ICON),
237+
width: 70.0,
238+
height: 70.0),
196239
),
197240
Container(
198-
child: Text(GSYLocalizations.i18n(context).app_empty, style: GSYConstant.normalText),
241+
child: Text(GSYLocalizations.i18n(context).app_empty,
242+
style: GSYConstant.normalText),
199243
),
200244
],
201245
),
@@ -254,7 +298,8 @@ class TrendPageState extends State<TrendPage> with AutomaticKeepAliveClientMixin
254298
}
255299

256300
///嵌套可滚动头部
257-
List<Widget> _sliverBuilder(BuildContext context, bool innerBoxIsScrolled, Store store) {
301+
List<Widget> _sliverBuilder(
302+
BuildContext context, bool innerBoxIsScrolled, Store store) {
258303
return <Widget>[
259304
///动态头部
260305
SliverPersistentHeader(
@@ -270,13 +315,15 @@ class TrendPageState extends State<TrendPage> with AutomaticKeepAliveClientMixin
270315
curve: Curves.bounceInOut,
271316
duration: const Duration(milliseconds: 10),
272317
),
273-
builder: (BuildContext context, double shrinkOffset, bool overlapsContent) {
318+
builder: (BuildContext context, double shrinkOffset,
319+
bool overlapsContent) {
274320
///根据数值计算偏差
275321
var lr = 10 - shrinkOffset / 65 * 10;
276322
var radius = Radius.circular(4 - shrinkOffset / 65 * 4);
277323
return SizedBox.expand(
278324
child: Padding(
279-
padding: EdgeInsets.only(top: lr, bottom: 15, left: lr, right: lr),
325+
padding:
326+
EdgeInsets.only(top: lr, bottom: 15, left: lr, right: lr),
280327
child: _renderHeader(store, radius),
281328
),
282329
);

pubspec.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ packages:
2929
url: "https://pub.flutter-io.cn"
3030
source: hosted
3131
version: "0.3.4+8"
32+
animations:
33+
dependency: "direct main"
34+
description:
35+
name: animations
36+
url: "https://pub.flutter-io.cn"
37+
source: hosted
38+
version: "1.0.0+5"
3239
args:
3340
dependency: transitive
3441
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ dependencies:
4646
graphql: 2.1.0
4747
flutter_json_widget: 1.0.2
4848
simple_animations: 1.3.4
49+
animations: 1.0.0+5
4950
flutter_localizations:
5051
sdk: flutter
5152
photo_view:

0 commit comments

Comments
 (0)