message_page.dart
11.4 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/pages/message/message_online_check_page.dart';
import 'package:one_key/pages/message/message_treated_page.dart';
import 'package:one_key/pages/message/message_untreated_page.dart';
import 'package:one_key/provider/message_dialog_model.dart';
import 'package:one_key/provider/message_model.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/event_bus.dart';
import 'package:one_key/widgets/app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';
import 'message_online_page.dart';
import 'message_order_page.dart';
/*
消息中心
*/
class MessagePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return new MessagePageState();
}
}
class MessagePageState extends State<MessagePage>
with TickerProviderStateMixin {
Color selectedColor = MyColours.color_ffffff;
Color unSelectedColor = MyColours.color_BFC4D4;
TabController tabController;
MessageModel messageModel;
UserModel userModel;
MessageDialogModel messageDialogModel;
// int selectIndex = 0;
@override
void initState() {
super.initState();
tabController = TabController(length: 2, vsync: this);
tabController.addListener(() {
//点击tab时或滑动tab回调一次
// if (tabController.index.toDouble() == tabController.animation.value) {
// getMessage(index: tabController.index);
// selectIndex = tabController.index;
setState(() {});
// }
});
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
// getMessage(index: 0);
});
//刷新未读数
bus.on("refresh_untreated_num", (arg) {
_getUnMsgNum();
});
//移除在线预订消息
bus.on("remove_untreated_message", (args) {
messageModel.removeUntreatedMessageByMid(args.toString());
messageDialogModel.removeMessage(args.toString());
});
}
//三种分类各自的未读消息数目
_getUnMsgNum() async {
if (mounted) {
Map<String, String> params = {
"sid": userModel.user.sellerid,
// "type_id": "10", //1提前点餐2内部预订10在线预订
// "status": '0',
"offset": '0',
"limit": "1000",
};
await messageModel.getNewGetUntreatedMsgNum(context, params,
showLoading: false);
}
}
//获取在线预订消息status 0未处理 1已处理
// getMessage({bool showLoading = true, int index}) async {
// String typeId = '';
// if (index == 0) {
// typeId = '10';
// } else if (index == 1) {
// typeId = '1';
// } else if (index == 2) {
// typeId = '12';
// }
// Map<String, String> params = {
// "sid": userModel.user.sellerid,
// "type_id": typeId, //1提前点餐2内部预订10在线预订
// "status": '0',
// "offset": '0',
// "limit": "20",
// };
// await messageModel.getMessages(context, params, showLoading: showLoading);
// _getUnMsgNum();
// }
@override
void dispose() {
super.dispose();
messageModel.pageStateUn = PageState.Loading;
messageModel.pageState = PageState.Loading;
messageModel.notifyListeners();
bus.off("refresh_untreated_num");
bus.off("remove_untreated_message");
}
@override
Widget build(BuildContext context) {
messageModel = Provider.of<MessageModel>(context, listen: true);
userModel = Provider.of<UserModel>(context, listen: false);
messageDialogModel =
Provider.of<MessageDialogModel>(context, listen: false);
return Container(
width: double.infinity,
height: double.infinity,
color: MyColours.color_ffffff,
child: Column(
children: <Widget>[
MyAppBar(
"消息中心",
showBack: false,
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(24 * 2)),
child: TabBar(
controller: tabController,
isScrollable: true,
labelPadding: EdgeInsets.zero, //tabs控件之间的间距
tabs: [
Tab(
child: Container(
width: (ScreenUtil().screenWidth -
ScreenUtil().setWidth(24 * 2 * 2)) /
2,
height: ScreenUtil().setWidth(36 * 2),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
width: ScreenUtil().setWidth(2),
color: tabController.index == 0
? MyColours.color_438E93
: MyColours.color_BFC4D4),
left: BorderSide(
width: ScreenUtil().setWidth(2),
color: tabController.index == 0
? MyColours.color_438E93
: MyColours.color_BFC4D4),
top: BorderSide(
width: ScreenUtil().setWidth(2),
color: tabController.index == 0
? MyColours.color_438E93
: MyColours.color_BFC4D4),
right: BorderSide(
width: ScreenUtil().setWidth(2),
color: tabController.index == 0
? MyColours.color_438E93
: MyColours.color_BFC4D4)),
borderRadius: BorderRadius.only(
topLeft:
Radius.circular(ScreenUtil().setWidth(16)),
bottomLeft:
Radius.circular(ScreenUtil().setWidth(16))),
color: tabController.index == 0
? MyColours.color_438E93
: MyColours.color_ffffff),
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("未处理",
style: TextStyle(
color: tabController.index == 0
? selectedColor
: unSelectedColor,
fontSize: tabController.index == 0
? ScreenUtil().setSp(32)
: ScreenUtil().setSp(24),
)),
messageModel.allUnNum > 0
? Container(
width: ScreenUtil().setWidth(36),
height: ScreenUtil().setWidth(36),
margin: EdgeInsets.only(
left: ScreenUtil().setWidth(20)),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
ScreenUtil().setWidth(36)),
color: MyColours.color_E34D59),
alignment: Alignment.center,
child: Text("${messageModel.allUnNum}",
style: TextStyle(
color: MyColours.color_ffffff,
fontSize: ScreenUtil().setSp(28),
)),
)
: SizedBox(),
],
),
),
),
Tab(
child: Container(
width: (ScreenUtil().screenWidth -
ScreenUtil().setWidth(24 * 2 * 2)) /
2,
height: ScreenUtil().setWidth(36 * 2),
decoration: BoxDecoration(
border: Border(
left: BorderSide(
width: ScreenUtil().setWidth(2),
color: tabController.index == 1
? MyColours.color_438E93
: MyColours.color_BFC4D4),
bottom: BorderSide(
width: ScreenUtil().setWidth(2),
color: tabController.index == 1
? MyColours.color_438E93
: MyColours.color_BFC4D4),
right: BorderSide(
width: ScreenUtil().setWidth(2),
color: tabController.index == 1
? MyColours.color_438E93
: MyColours.color_BFC4D4),
top: BorderSide(
width: ScreenUtil().setWidth(2),
color: tabController.index == 1
? MyColours.color_438E93
: MyColours.color_BFC4D4)),
borderRadius: BorderRadius.only(
topRight:
Radius.circular(ScreenUtil().setWidth(16)),
bottomRight:
Radius.circular(ScreenUtil().setWidth(16))),
color: tabController.index == 1
? MyColours.color_438E93
: MyColours.color_ffffff),
alignment: Alignment.center,
child: Text(
"已处理",
style: TextStyle(
color: tabController.index == 1
? selectedColor
: unSelectedColor,
fontSize: tabController.index == 1
? ScreenUtil().setSp(32)
: ScreenUtil().setSp(24)),
)),
),
],
indicatorColor: Colors.transparent,
indicatorSize: TabBarIndicatorSize.tab,
// indicatorPadding: EdgeInsets.only(
// left: ScreenUtil().setWidth(16),
// right: ScreenUtil().setWidth(32)),
// indicatorWeight: ScreenUtil().setWidth(6.0),
)),
VEmptyView(11),
Expanded(
child: TabBarView(controller: tabController, children: [
MessageUntreatedPage(),
MessageTreatedPage(),
// MessageOnlineCheckPage()
]),
)
],
),
);
}
}