Skip to content

Commit b5d7cc2

Browse files
committed
文件列表增加返回按键处理逻辑
1 parent 586e828 commit b5d7cc2

File tree

5 files changed

+101
-61
lines changed

5 files changed

+101
-61
lines changed

lib/page/RepositoryDetailPage.dart

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class RepositoryDetailPage extends StatefulWidget {
2929
_RepositoryDetailPageState createState() => _RepositoryDetailPageState(userName, reposName);
3030
}
3131

32-
3332
class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
3433
ReposHeaderViewModel reposHeaderViewModel = new ReposHeaderViewModel();
3534

@@ -43,7 +42,7 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
4342

4443
final TarWidgetControl tarBarControl = new TarWidgetControl();
4544

46-
final BranchControl branchControl = new BranchControl("master");
45+
final ReposDetailParentControl reposDetailParentControl = new ReposDetailParentControl("master");
4746

4847
final PageController topPageControl = new PageController();
4948

@@ -60,7 +59,7 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
6059
_RepositoryDetailPageState(this.userName, this.reposName);
6160

6261
_getReposDetail() async {
63-
var result = await ReposDao.getRepositoryDetailDao(userName, reposName, branchControl.currentBranch);
62+
var result = await ReposDao.getRepositoryDetailDao(userName, reposName, reposDetailParentControl.currentBranch);
6463
if (result != null && result.result) {
6564
setState(() {
6665
reposDetailInfoPageControl.repository = result.data;
@@ -175,9 +174,9 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
175174
Navigator.pop(context);
176175
});
177176
}),
178-
_renderBranchPopItem(branchControl.currentBranch, branchList, (value) {
177+
_renderBranchPopItem(reposDetailParentControl.currentBranch, branchList, (value) {
179178
setState(() {
180-
branchControl.currentBranch = value;
179+
reposDetailParentControl.currentBranch = value;
181180
tarBarControl.footerButton = _getBottomWidget();
182181
});
183182
if (infoListKey.currentState != null && infoListKey.currentState.mounted) {
@@ -207,6 +206,7 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
207206
return new FlatButton(
208207
padding: EdgeInsets.all(0.0),
209208
onPressed: () {
209+
reposDetailParentControl.currentIndex = i;
210210
topPageControl.jumpTo(MediaQuery.of(context).size.width * i);
211211
},
212212
child: new Text(
@@ -227,8 +227,10 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
227227
return [
228228
///Release Page
229229
new GSYOptionModel(GSYStrings.repos_option_release, GSYStrings.repos_option_release, (model) {
230-
String releaseUrl = reposDetailInfoPageControl.repository == null ? GSYStrings.app_default_share_url : reposDetailInfoPageControl.repository.htmlUrl + "/releases";
231-
String tagUrl = reposDetailInfoPageControl.repository == null ? GSYStrings.app_default_share_url : reposDetailInfoPageControl.repository.htmlUrl + "/tags";
230+
String releaseUrl =
231+
reposDetailInfoPageControl.repository == null ? GSYStrings.app_default_share_url : reposDetailInfoPageControl.repository.htmlUrl + "/releases";
232+
String tagUrl =
233+
reposDetailInfoPageControl.repository == null ? GSYStrings.app_default_share_url : reposDetailInfoPageControl.repository.htmlUrl + "/tags";
232234
NavigatorUtils.goReleasePage(context, userName, reposName, releaseUrl, tagUrl);
233235
}),
234236
];
@@ -245,22 +247,26 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
245247
Widget build(BuildContext context) {
246248
Widget widget = new GSYCommonOptionWidget(titleOptionControl, otherList: _getMoreOtherItem());
247249
return new GSYTabBarWidget(
248-
type: GSYTabBarWidget.TOP_TAB,
249-
tarWidgetControl: tarBarControl,
250-
tabItems: _renderTabItem(),
251-
tabViews: [
252-
new ReposDetailInfoPage(reposDetailInfoPageControl, userName, reposName, branchControl, key: infoListKey),
253-
new RepositoryDetailReadmePage(userName, reposName, branchControl, key: readmeKey),
254-
new RepositoryDetailIssuePage(userName, reposName),
255-
new RepositoryDetailFileListPage(userName, reposName, branchControl, key: fileListKey),
256-
],
257-
topPageControl: topPageControl,
258-
backgroundColor: GSYColors.primarySwatch,
259-
indicatorColor: Colors.white,
260-
title: new GSYTitleBar(
261-
reposName,
262-
rightWidget: widget,
263-
));
250+
type: GSYTabBarWidget.TOP_TAB,
251+
tarWidgetControl: tarBarControl,
252+
tabItems: _renderTabItem(),
253+
tabViews: [
254+
new ReposDetailInfoPage(reposDetailInfoPageControl, userName, reposName, reposDetailParentControl, key: infoListKey),
255+
new RepositoryDetailReadmePage(userName, reposName, reposDetailParentControl, key: readmeKey),
256+
new RepositoryDetailIssuePage(userName, reposName),
257+
new RepositoryDetailFileListPage(userName, reposName, reposDetailParentControl, key: fileListKey),
258+
],
259+
topPageControl: topPageControl,
260+
backgroundColor: GSYColors.primarySwatch,
261+
indicatorColor: Colors.white,
262+
title: new GSYTitleBar(
263+
reposName,
264+
rightWidget: widget,
265+
),
266+
onPageChanged: (index) {
267+
reposDetailParentControl.currentIndex = index;
268+
},
269+
);
264270
}
265271
}
266272

@@ -275,8 +281,10 @@ class BottomStatusModel {
275281
BottomStatusModel(this.watchText, this.starText, this.watchIcon, this.starIcon, this.watch, this.star);
276282
}
277283

278-
class BranchControl {
284+
class ReposDetailParentControl {
285+
int currentIndex = 0;
286+
279287
String currentBranch;
280288

281-
BranchControl(this.currentBranch);
289+
ReposDetailParentControl(this.currentBranch);
282290
}

lib/page/RepositoryDetailReadmePage.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ class RepositoryDetailReadmePage extends StatefulWidget {
1616

1717
final String reposName;
1818

19-
final BranchControl branchControl;
19+
final ReposDetailParentControl reposDetailParentControl;
2020

21-
RepositoryDetailReadmePage(this.userName, this.reposName, this.branchControl, {Key key}) : super(key: key);
21+
RepositoryDetailReadmePage(this.userName, this.reposName, this.reposDetailParentControl, {Key key}) : super(key: key);
2222

2323
@override
24-
RepositoryDetailReadmePageState createState() => RepositoryDetailReadmePageState(userName, reposName, branchControl);
24+
RepositoryDetailReadmePageState createState() => RepositoryDetailReadmePageState(userName, reposName, reposDetailParentControl);
2525
}
2626

2727
// ignore: mixin_inherits_from_not_object
@@ -30,16 +30,16 @@ class RepositoryDetailReadmePageState extends State<RepositoryDetailReadmePage>
3030

3131
final String reposName;
3232

33-
final BranchControl branchControl;
33+
final ReposDetailParentControl reposDetailParentControl;
3434

3535
bool isShow = false;
3636

3737
String markdownData;
3838

39-
RepositoryDetailReadmePageState(this.userName, this.reposName, this.branchControl);
39+
RepositoryDetailReadmePageState(this.userName, this.reposName, this.reposDetailParentControl);
4040

4141
refreshReadme() {
42-
ReposDao.getRepositoryDetailReadmeDao(userName, reposName, branchControl.currentBranch).then((res) {
42+
ReposDao.getRepositoryDetailReadmeDao(userName, reposName, reposDetailParentControl.currentBranch).then((res) {
4343
if (res != null && res.result) {
4444
if (isShow) {
4545
setState(() {

lib/page/RepositoryFileListPage.dart

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:flutter/material.dart';
24
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
35
import 'package:gsy_github_app_flutter/common/model/FileModel.dart';
@@ -20,12 +22,12 @@ class RepositoryDetailFileListPage extends StatefulWidget {
2022

2123
final String reposName;
2224

23-
final BranchControl branchControl;
25+
final ReposDetailParentControl reposDetailParentControl;
2426

25-
RepositoryDetailFileListPage(this.userName, this.reposName, this.branchControl, {Key key}) : super(key: key);
27+
RepositoryDetailFileListPage(this.userName, this.reposName, this.reposDetailParentControl, {Key key}) : super(key: key);
2628

2729
@override
28-
RepositoryDetailFileListPageState createState() => RepositoryDetailFileListPageState(userName, reposName, branchControl);
30+
RepositoryDetailFileListPageState createState() => RepositoryDetailFileListPageState(userName, reposName, reposDetailParentControl);
2931
}
3032

3133
// ignore: mixin_inherits_from_not_object
@@ -34,7 +36,7 @@ class RepositoryDetailFileListPageState extends GSYListState<RepositoryDetailFil
3436

3537
final String reposName;
3638

37-
final BranchControl branchControl;
39+
final ReposDetailParentControl reposDetailParentControl;
3840

3941
String path = '';
4042

@@ -43,7 +45,7 @@ class RepositoryDetailFileListPageState extends GSYListState<RepositoryDetailFil
4345

4446
List<String> headerList = ["."];
4547

46-
RepositoryDetailFileListPageState(this.userName, this.reposName, this.branchControl);
48+
RepositoryDetailFileListPageState(this.userName, this.reposName, this.reposDetailParentControl);
4749

4850
///渲染文件item
4951
_renderEventItem(index) {
@@ -128,14 +130,27 @@ class RepositoryDetailFileListPageState extends GSYListState<RepositoryDetailFil
128130
reposName: reposName,
129131
userName: userName,
130132
path: path,
131-
branch: branchControl.currentBranch,
133+
branch: reposDetailParentControl.currentBranch,
132134
);
133135
}
134136
}
135137
}
136138

137139
_getDataLogic(String searchString) async {
138-
return await ReposDao.getReposFileDirDao(userName, reposName, path: path, branch: branchControl.currentBranch);
140+
return await ReposDao.getReposFileDirDao(userName, reposName, path: path, branch: reposDetailParentControl.currentBranch);
141+
}
142+
143+
/// 返回按键逻辑
144+
Future<bool> _dialogExitApp(BuildContext context) {
145+
if (reposDetailParentControl.currentIndex != 3) {
146+
return Future.value(true);
147+
}
148+
if (headerList.length == 1) {
149+
return Future.value(true);
150+
} else {
151+
_resolveHeaderClick(headerList.length - 2);
152+
return Future.value(false);
153+
}
139154
}
140155

141156
@override
@@ -168,12 +183,17 @@ class RepositoryDetailFileListPageState extends GSYListState<RepositoryDetailFil
168183
leading: new Container(),
169184
elevation: 0.0,
170185
),
171-
body: GSYPullLoadWidget(
172-
pullLoadWidgetControl,
173-
(BuildContext context, int index) => _renderEventItem(index),
174-
handleRefresh,
175-
onLoadMore,
176-
refreshKey: refreshIndicatorKey,
186+
body: WillPopScope(
187+
onWillPop: () {
188+
return _dialogExitApp(context);
189+
},
190+
child: GSYPullLoadWidget(
191+
pullLoadWidgetControl,
192+
(BuildContext context, int index) => _renderEventItem(index),
193+
handleRefresh,
194+
onLoadMore,
195+
refreshKey: refreshIndicatorKey,
196+
),
177197
),
178198
);
179199
}

lib/page/RepostoryDetailInfoPage.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class ReposDetailInfoPage extends StatefulWidget {
2121
final String reposName;
2222
final ReposDetailInfoPageControl reposDetailInfoPageControl;
2323

24-
final BranchControl branchControl;
24+
final ReposDetailParentControl reposDetailParentControl;
2525

26-
ReposDetailInfoPage(this.reposDetailInfoPageControl, this.userName, this.reposName, this.branchControl, {Key key}) : super(key: key);
26+
ReposDetailInfoPage(this.reposDetailInfoPageControl, this.userName, this.reposName, this.reposDetailParentControl, {Key key}) : super(key: key);
2727

2828
@override
29-
ReposDetailInfoPageState createState() => ReposDetailInfoPageState(reposDetailInfoPageControl, userName, reposName, branchControl);
29+
ReposDetailInfoPageState createState() => ReposDetailInfoPageState(reposDetailInfoPageControl, userName, reposName, reposDetailParentControl);
3030
}
3131

3232
// ignore: mixin_inherits_from_not_object
@@ -37,11 +37,11 @@ class ReposDetailInfoPageState extends GSYListState<ReposDetailInfoPage> {
3737

3838
final ReposDetailInfoPageControl reposDetailInfoPageControl;
3939

40-
final BranchControl branchControl;
40+
final ReposDetailParentControl reposDetailParentControl;
4141

4242
int selectIndex = 0;
4343

44-
ReposDetailInfoPageState(this.reposDetailInfoPageControl, this.userName, this.reposName, this.branchControl);
44+
ReposDetailInfoPageState(this.reposDetailInfoPageControl, this.userName, this.reposName, this.reposDetailParentControl);
4545

4646
_renderEventItem(index) {
4747
if (index == 0) {
@@ -72,9 +72,9 @@ class ReposDetailInfoPageState extends GSYListState<ReposDetailInfoPage> {
7272

7373
_getDataLogic() async {
7474
if (selectIndex == 1) {
75-
return await ReposDao.getReposCommitsDao(userName, reposName, page: page, branch: branchControl.currentBranch);
75+
return await ReposDao.getReposCommitsDao(userName, reposName, page: page, branch: reposDetailParentControl.currentBranch);
7676
}
77-
return await ReposDao.getRepositoryEventDao(userName, reposName, page: page, branch: branchControl.currentBranch);
77+
return await ReposDao.getRepositoryEventDao(userName, reposName, page: page, branch: reposDetailParentControl.currentBranch);
7878
}
7979

8080
@override

lib/widget/GSYTabBarWidget.dart

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class GSYTabBarWidget extends StatefulWidget {
2929

3030
final PageController topPageControl;
3131

32+
final ValueChanged<int> onPageChanged;
33+
3234
GSYTabBarWidget({
3335
Key key,
3436
this.type,
@@ -41,11 +43,23 @@ class GSYTabBarWidget extends StatefulWidget {
4143
this.floatingActionButton,
4244
this.tarWidgetControl,
4345
this.topPageControl,
46+
this.onPageChanged,
4447
}) : super(key: key);
4548

4649
@override
4750
_GSYTabBarState createState() => new _GSYTabBarState(
48-
type, tabItems, tabViews, backgroundColor, indicatorColor, title, drawer, floatingActionButton, tarWidgetControl, topPageControl);
51+
type,
52+
tabItems,
53+
tabViews,
54+
backgroundColor,
55+
indicatorColor,
56+
title,
57+
drawer,
58+
floatingActionButton,
59+
tarWidgetControl,
60+
topPageControl,
61+
onPageChanged,
62+
);
4963
}
5064

5165
// ignore: mixin_inherits_from_not_object
@@ -70,29 +84,24 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
7084

7185
final PageController _pageController;
7286

87+
final ValueChanged<int> _onPageChanged;
88+
7389
_GSYTabBarState(this._type, this._tabItems, this._tabViews, this._backgroundColor, this._indicatorColor, this._title, this._drawer,
74-
this._floatingActionButton, this._tarWidgetControl, this._pageController)
90+
this._floatingActionButton, this._tarWidgetControl, this._pageController, this._onPageChanged)
7591
: super();
7692

7793
TabController _tabController;
7894

7995
@override
8096
void initState() {
8197
super.initState();
82-
//if (this._type == GSYTabBarWidget.BOTTOM_TAB) {
83-
_tabController = new TabController(
84-
vsync: this, //动画效果的异步处理,默认格式,背下来即可
85-
length: _tabItems.length //需要控制的Tab页数量
86-
);
87-
//}
98+
_tabController = new TabController(vsync: this, length: _tabItems.length);
8899
}
89100

90101
///整个页面dispose时,记得把控制器也dispose掉,释放内存
91102
@override
92103
void dispose() {
93-
//if (this._type == GSYTabBarWidget.BOTTOM_TAB) {
94104
_tabController.dispose();
95-
//}
96105
super.dispose();
97106
}
98107

@@ -117,6 +126,9 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
117126
children: _tabViews,
118127
onPageChanged: (index) {
119128
_tabController.animateTo(index);
129+
if (_onPageChanged != null) {
130+
_onPageChanged(index);
131+
}
120132
},
121133
),
122134
);

0 commit comments

Comments
 (0)