|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart'; |
| 3 | +import 'package:gsy_github_app_flutter/common/net/Address.dart'; |
| 4 | +import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart'; |
| 5 | +import 'package:gsy_github_app_flutter/widget/GSYCommonOptionWidget.dart'; |
| 6 | +import 'package:gsy_github_app_flutter/widget/GSYListState.dart'; |
| 7 | +import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart'; |
| 8 | +import 'package:gsy_github_app_flutter/widget/GSYSelectItemWidget.dart'; |
| 9 | +import 'package:gsy_github_app_flutter/widget/GSYTitleBar.dart'; |
| 10 | +import 'package:gsy_github_app_flutter/widget/ReleaseItem.dart'; |
| 11 | + |
| 12 | +/** |
| 13 | + * 版本页 |
| 14 | + * Created by guoshuyu |
| 15 | + * Date: 2018-07-30 |
| 16 | + */ |
| 17 | + |
| 18 | +class ReleasePage extends StatefulWidget { |
| 19 | + final String userName; |
| 20 | + |
| 21 | + final String reposName; |
| 22 | + |
| 23 | + ReleasePage(this.userName, this.reposName); |
| 24 | + |
| 25 | + @override |
| 26 | + _ReleasePageState createState() => _ReleasePageState(this.userName, this.reposName); |
| 27 | +} |
| 28 | + |
| 29 | +// ignore: mixin_inherits_from_not_object |
| 30 | +class _ReleasePageState extends GSYListState<ReleasePage> { |
| 31 | + final String userName; |
| 32 | + |
| 33 | + final String reposName; |
| 34 | + |
| 35 | + int selectIndex; |
| 36 | + |
| 37 | + _ReleasePageState(this.userName, this.reposName); |
| 38 | + |
| 39 | + _renderEventItem(index) { |
| 40 | + ReleaseItemViewModel releaseItemViewModel = pullLoadWidgetControl.dataList[index]; |
| 41 | + return new ReleaseItem( |
| 42 | + releaseItemViewModel, |
| 43 | + onPressed: () {}, |
| 44 | + onLongPress: () {}, |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + _resolveSelectIndex() { |
| 49 | + clearData(); |
| 50 | + showRefreshLoading(); |
| 51 | + } |
| 52 | + |
| 53 | + _getDataLogic() async { |
| 54 | + return await ReposDao.getRepositoryReleaseDao(userName, reposName, page, needHtml: false, release: selectIndex == 0); |
| 55 | + } |
| 56 | + |
| 57 | + @override |
| 58 | + bool get wantKeepAlive => false; |
| 59 | + |
| 60 | + @override |
| 61 | + bool get needHeader => false; |
| 62 | + |
| 63 | + @override |
| 64 | + bool get isRefreshFirst => true; |
| 65 | + |
| 66 | + @override |
| 67 | + requestLoadMore() async { |
| 68 | + return await _getDataLogic(); |
| 69 | + } |
| 70 | + |
| 71 | + @override |
| 72 | + requestRefresh() async { |
| 73 | + return await _getDataLogic(); |
| 74 | + } |
| 75 | + |
| 76 | + @override |
| 77 | + Widget build(BuildContext context) { |
| 78 | + super.build(context); // See AutomaticKeepAliveClientMixin. |
| 79 | + String url = Address.hostWeb + userName + "/" + reposName + "/releases"; |
| 80 | + return new Scaffold( |
| 81 | + backgroundColor: Color(GSYColors.mainBackgroundColor), |
| 82 | + appBar: new AppBar( |
| 83 | + title: GSYTitleBar( |
| 84 | + reposName, |
| 85 | + rightWidget: new GSYCommonOptionWidget(url), |
| 86 | + ), |
| 87 | + bottom: new GSYSelectItemWidget( |
| 88 | + [ |
| 89 | + GSYStrings.release_tab_release, |
| 90 | + GSYStrings.release_tab_tag, |
| 91 | + ], |
| 92 | + (selectIndex) { |
| 93 | + this.selectIndex = selectIndex; |
| 94 | + _resolveSelectIndex(); |
| 95 | + }, |
| 96 | + height: 30.0, |
| 97 | + margin: const EdgeInsets.all(0.0), |
| 98 | + elevation: 0.0, |
| 99 | + ), |
| 100 | + elevation: 4.0, |
| 101 | + ), |
| 102 | + body: GSYPullLoadWidget( |
| 103 | + pullLoadWidgetControl, |
| 104 | + (BuildContext context, int index) => _renderEventItem(index), |
| 105 | + handleRefresh, |
| 106 | + onLoadMore, |
| 107 | + refreshKey: refreshIndicatorKey, |
| 108 | + ), |
| 109 | + ); |
| 110 | + } |
| 111 | +} |
0 commit comments