forked from CarGuo/gsy_github_app_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotifyPage.dart
More file actions
150 lines (134 loc) · 4.61 KB
/
NotifyPage.dart
File metadata and controls
150 lines (134 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import 'package:flutter/material.dart';
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
import 'package:gsy_github_app_flutter/widget/GSYSelectItemWidget.dart';
import 'package:gsy_github_app_flutter/widget/GSYTitleBar.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:gsy_github_app_flutter/common/model/Notification.dart' as Model;
/**
* 通知消息
* Created by guoshuyu
* Date: 2018-07-24
*/
class NotifyPage extends StatefulWidget {
NotifyPage();
@override
_NotifyPageState createState() => _NotifyPageState();
}
// ignore: mixin_inherits_from_not_object
class _NotifyPageState extends State<NotifyPage> with AutomaticKeepAliveClientMixin<NotifyPage>, GSYListState<NotifyPage> {
final SlidableController slidableController = new SlidableController();
int selectIndex = 0;
_NotifyPageState();
_renderItem(index) {
Model.Notification notification = pullLoadWidgetControl.dataList[index];
if (selectIndex != 0) {
return _renderEventItem(notification);
}
return new Slidable(
controller: slidableController,
delegate: new SlidableDrawerDelegate(),
actionExtentRatio: 0.25,
child: _renderEventItem(notification),
secondaryActions: <Widget>[
new IconSlideAction(
caption: CommonUtils.getLocale(context).notify_readed,
color: Colors.redAccent,
icon: Icons.delete,
onTap: () {
UserDao.setNotificationAsReadDao(notification.id.toString()).then((res) {
showRefreshLoading();
});
},
),
],
);
}
_renderEventItem(Model.Notification notification) {
EventViewModel eventViewModel = EventViewModel.fromNotify(context, notification);
return new EventItem(eventViewModel, onPressed: () {
if (notification.unread) {
UserDao.setNotificationAsReadDao(notification.id.toString());
}
if (notification.subject.type == 'Issue') {
String url = notification.subject.url;
List<String> tmp = url.split("/");
String number = tmp[tmp.length - 1];
String userName = notification.repository.owner.login;
String reposName = notification.repository.name;
NavigatorUtils.goIssueDetail(context, userName, reposName, number, needRightLocalIcon: true).then((res) {
showRefreshLoading();
});
}
}, needImage: false);
}
_resolveSelectIndex() {
clearData();
showRefreshLoading();
}
_getDataLogic() async {
return await UserDao.getNotifyDao(selectIndex == 2, selectIndex == 1, page);
}
@override
bool get wantKeepAlive => true;
@override
bool get needHeader => false;
@override
bool get isRefreshFirst => true;
@override
requestLoadMore() async {
return await _getDataLogic();
}
@override
requestRefresh() async {
return await _getDataLogic();
}
@override
Widget build(BuildContext context) {
super.build(context); // See AutomaticKeepAliveClientMixin.
return new Scaffold(
backgroundColor: Color(GSYColors.mainBackgroundColor),
appBar: new AppBar(
title: GSYTitleBar(
CommonUtils.getLocale(context).notify_title,
iconData: GSYICons.NOTIFY_ALL_READ,
needRightLocalIcon: true,
onPressed: () {
CommonUtils.showLoadingDialog(context);
UserDao.setAllNotificationAsReadDao().then((res) {
Navigator.pop(context);
_resolveSelectIndex();
});
},
),
bottom: new GSYSelectItemWidget(
[
CommonUtils.getLocale(context).notify_tab_unread,
CommonUtils.getLocale(context).notify_tab_part,
CommonUtils.getLocale(context).notify_tab_all,
],
(selectIndex) {
this.selectIndex = selectIndex;
_resolveSelectIndex();
},
height: 30.0,
margin: const EdgeInsets.all(0.0),
elevation: 0.0,
),
elevation: 4.0,
),
body: GSYPullLoadWidget(
pullLoadWidgetControl,
(BuildContext context, int index) => _renderItem(index),
handleRefresh,
onLoadMore,
refreshKey: refreshIndicatorKey,
),
);
}
}