|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:gsy_github_app_flutter/common/dao/UserDao.dart'; |
| 3 | +import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart'; |
| 4 | +import 'package:gsy_github_app_flutter/widget/EventItem.dart'; |
| 5 | +import 'package:gsy_github_app_flutter/widget/GSYListState.dart'; |
| 6 | +import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart'; |
| 7 | +import 'package:gsy_github_app_flutter/widget/GSYSelectItemWidget.dart'; |
| 8 | + |
| 9 | +/** |
| 10 | + * Created by guoshuyu |
| 11 | + * Date: 2018-07-24 |
| 12 | + */ |
| 13 | + |
| 14 | +class NotifyPage extends StatefulWidget { |
| 15 | + NotifyPage(); |
| 16 | + |
| 17 | + @override |
| 18 | + _NotifyPageState createState() => _NotifyPageState(); |
| 19 | +} |
| 20 | + |
| 21 | +// ignore: mixin_inherits_from_not_object |
| 22 | +class _NotifyPageState extends GSYListState<NotifyPage> { |
| 23 | + int selectIndex; |
| 24 | + |
| 25 | + _NotifyPageState(); |
| 26 | + |
| 27 | + _renderEventItem(index) { |
| 28 | + EventViewModel eventViewModel = pullLoadWidgetControl.dataList[index]; |
| 29 | + return new EventItem( |
| 30 | + eventViewModel, |
| 31 | + onPressed: () {}, |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + _resolveSelectIndex() { |
| 36 | + clearData(); |
| 37 | + showRefreshLoading(); |
| 38 | + } |
| 39 | + |
| 40 | + _getDataLogic() async { |
| 41 | + return await UserDao.getNotifyDao(selectIndex == 2, selectIndex == 1, page); |
| 42 | + } |
| 43 | + |
| 44 | + @override |
| 45 | + bool get wantKeepAlive => true; |
| 46 | + |
| 47 | + @override |
| 48 | + bool get needHeader => false; |
| 49 | + |
| 50 | + @override |
| 51 | + bool get isRefreshFirst => true; |
| 52 | + |
| 53 | + @override |
| 54 | + requestLoadMore() async { |
| 55 | + return await _getDataLogic(); |
| 56 | + } |
| 57 | + |
| 58 | + @override |
| 59 | + requestRefresh() async { |
| 60 | + return await _getDataLogic(); |
| 61 | + } |
| 62 | + |
| 63 | + @override |
| 64 | + Widget build(BuildContext context) { |
| 65 | + super.build(context); // See AutomaticKeepAliveClientMixin. |
| 66 | + return new Scaffold( |
| 67 | + backgroundColor: Color(GSYColors.mainBackgroundColor), |
| 68 | + appBar: new AppBar( |
| 69 | + title: new Text(GSYStrings.notify_title), |
| 70 | + bottom: new GSYSelectItemWidget( |
| 71 | + [ |
| 72 | + GSYStrings.notify_tab_unread, |
| 73 | + GSYStrings.notify_tab_part, |
| 74 | + GSYStrings.notify_tab_all, |
| 75 | + ], |
| 76 | + (selectIndex) { |
| 77 | + this.selectIndex = selectIndex; |
| 78 | + _resolveSelectIndex(); |
| 79 | + }, |
| 80 | + elevation: 0.0, |
| 81 | + ), |
| 82 | + elevation: 4.0, |
| 83 | + ), |
| 84 | + body: GSYPullLoadWidget( |
| 85 | + pullLoadWidgetControl, |
| 86 | + (BuildContext context, int index) => _renderEventItem(index), |
| 87 | + handleRefresh, |
| 88 | + onLoadMore, |
| 89 | + refreshKey: refreshIndicatorKey, |
| 90 | + ), |
| 91 | + ); |
| 92 | + } |
| 93 | +} |
0 commit comments