X Tutup
Skip to content

Commit c8e05da

Browse files
committed
fix welcome
1 parent 504fcf7 commit c8e05da

File tree

5 files changed

+47
-22
lines changed

5 files changed

+47
-22
lines changed

RECORD.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ flutter packages pub run build_runner build
2727

2828
### 如何主动刷新refresh,如何设置appbar上的leading和bottom,如何设置tabbar的live
2929

30-
https://github.com/flutter/flutter/issues/19030 没有webview,残念
30+
https://github.com/flutter/flutter/issues/19030 没有webview,残念
31+
32+
https://github.com/flutter/flutter/issues/19030#issuecomment-406656714
33+
34+
https://github.com/flutter/flutter/issues/11895#issuecomment-406832395

lib/page/RepositoryDetailPage.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
4444

4545
final BranchControl branchControl = new BranchControl("master");
4646

47-
final GlobalKey<RepositoryDetailFileListPageState> fileListKey = new GlobalKey<RepositoryDetailFileListPageState>();
47+
GlobalKey<RepositoryDetailFileListPageState> fileListKey = new GlobalKey<RepositoryDetailFileListPageState>();
4848

49-
final GlobalKey<ReposDetailInfoPageState> infoListKey = new GlobalKey<ReposDetailInfoPageState>();
49+
GlobalKey<ReposDetailInfoPageState> infoListKey = new GlobalKey<ReposDetailInfoPageState>();
5050

5151
List<String> branchList = new List();
5252

@@ -192,9 +192,12 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
192192
branchControl.currentBranch = value;
193193
});
194194
_getReposDetail();
195-
//TODO 判断是否存在需要刷新
196-
//fileListKey.currentState.showRefreshLoading();
197-
infoListKey.currentState.showRefreshLoading();
195+
if (infoListKey.currentState != null && infoListKey.currentState.mounted) {
196+
infoListKey.currentState.showRefreshLoading();
197+
}
198+
if (fileListKey.currentState != null && fileListKey.currentState.mounted) {
199+
fileListKey.currentState.showRefreshLoading();
200+
}
198201
}),
199202
];
200203
return bottomWidget;
@@ -209,6 +212,8 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
209212

210213
@override
211214
Widget build(BuildContext context) {
215+
fileListKey = new GlobalKey<RepositoryDetailFileListPageState>();
216+
infoListKey = new GlobalKey<ReposDetailInfoPageState>();
212217
return new GSYTabBarWidget(
213218
type: GSYTabBarWidget.TOP_TAB,
214219
tarWidgetControl: tarBarControl,

lib/page/WelcomePage.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class WelcomePage extends StatelessWidget {
1717

1818
@override
1919
Widget build(BuildContext context) {
20-
Store<GSYState> store = StoreProvider.of(context);
20+
Store<GSYState> store = StoreProvider.of(context);
2121
new Future.delayed(const Duration(seconds: 2), () {
2222
UserDao.initUserInfo(store).then((res) {
2323
if (res != null && res.result) {
@@ -32,7 +32,7 @@ class WelcomePage extends StatelessWidget {
3232
return new Container(
3333
color: Colors.white,
3434
child: new Center(
35-
child: new Image(image: new AssetImage('static/images/logo.png'), width: 90.0, height: 90.0),
35+
child: new Image(image: new AssetImage('static/images/welcome.png')),
3636
),
3737
);
3838
},

lib/widget/GSYListState.dart

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
1111
*/
1212
// ignore: mixin_inherits_from_not_object
1313
abstract class GSYListState<T extends StatefulWidget> extends State<T> with AutomaticKeepAliveClientMixin {
14+
bool isShow = false;
15+
1416
bool isLoading = false;
1517

1618
int page = 1;
@@ -21,7 +23,6 @@ abstract class GSYListState<T extends StatefulWidget> extends State<T> with Auto
2123

2224
final GlobalKey<RefreshIndicatorState> refreshIndicatorKey = new GlobalKey<RefreshIndicatorState>();
2325

24-
2526
showRefreshLoading() {
2627
new Future.delayed(const Duration(seconds: 0), () {
2728
refreshIndicatorKey.currentState.show().then((e) {});
@@ -38,9 +39,11 @@ abstract class GSYListState<T extends StatefulWidget> extends State<T> with Auto
3839
var res = await requestRefresh();
3940
if (res != null && res.result) {
4041
pullLoadWidgetControl.dataList.clear();
41-
setState(() {
42-
pullLoadWidgetControl.dataList.addAll(res.data);
43-
});
42+
if (isShow) {
43+
setState(() {
44+
pullLoadWidgetControl.dataList.addAll(res.data);
45+
});
46+
}
4447
}
4548
resolveDataResult(res);
4649
isLoading = false;
@@ -56,9 +59,11 @@ abstract class GSYListState<T extends StatefulWidget> extends State<T> with Auto
5659
page++;
5760
var res = await requestLoadMore();
5861
if (res != null && res.result) {
59-
setState(() {
60-
pullLoadWidgetControl.dataList.addAll(res.data);
61-
});
62+
if (isShow) {
63+
setState(() {
64+
pullLoadWidgetControl.dataList.addAll(res.data);
65+
});
66+
}
6267
}
6368
resolveDataResult(res);
6469
isLoading = false;
@@ -67,16 +72,20 @@ abstract class GSYListState<T extends StatefulWidget> extends State<T> with Auto
6772

6873
@protected
6974
resolveDataResult(res) {
70-
setState(() {
71-
pullLoadWidgetControl.needLoadMore = (res != null && res.data != null && res.data.length == Config.PAGE_SIZE);
72-
});
75+
if (isShow) {
76+
setState(() {
77+
pullLoadWidgetControl.needLoadMore = (res != null && res.data != null && res.data.length == Config.PAGE_SIZE);
78+
});
79+
}
7380
}
7481

7582
@protected
7683
clearData() {
77-
setState(() {
78-
pullLoadWidgetControl.dataList.clear();
79-
});
84+
if (isShow) {
85+
setState(() {
86+
pullLoadWidgetControl.dataList.clear();
87+
});
88+
}
8089
}
8190

8291
///下拉刷新数据
@@ -103,11 +112,18 @@ abstract class GSYListState<T extends StatefulWidget> extends State<T> with Auto
103112

104113
@override
105114
void initState() {
115+
isShow = true;
106116
super.initState();
107117
pullLoadWidgetControl.needHeader = needHeader;
108118
pullLoadWidgetControl.dataList = getDataList;
109119
if (pullLoadWidgetControl.dataList.length == 0 && isRefreshFirst) {
110120
showRefreshLoading();
111121
}
112122
}
123+
124+
@override
125+
void dispose() {
126+
isShow = false;
127+
super.dispose();
128+
}
113129
}

lib/widget/GSYTabBarWidget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
7777
if (this._type == GSYTabBarWidget.BOTTOM_TAB) {
7878
_tabController = new TabController(
7979
vsync: this, //动画效果的异步处理,默认格式,背下来即可
80-
length: 3 //需要控制的Tab页数量
80+
length: _tabItems.length //需要控制的Tab页数量
8181
);
8282
}
8383
}

0 commit comments

Comments
 (0)
X Tutup