message_page.dart
5.45 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
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.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_199095;
Color unSelectedColor = MyColours.color_999999;
TabController tabController;
MessageModel messageModel;
UserModel userModel;
@override
void initState() {
// TODO: implement initState
super.initState();
tabController = TabController(length: 2, vsync: this);
tabController.addListener(() {
setState(() {});
});
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
_getUnMsgNum();
});
//刷新未读数
bus.on("refresh_untreated_num", (arg) {
_getUnMsgNum();
});
}
//三种分类各自的未读消息数目
_getUnMsgNum() async {
Map<String, String> params = {"sid": userModel.user.sellerid};
await messageModel.getUnMsgNum(context, params);
}
@override
Widget build(BuildContext context) {
messageModel = Provider.of<MessageModel>(context, listen: true);
userModel = Provider.of<UserModel>(context, listen: false);
return Container(
width: double.infinity,
height: double.infinity,
color: MyColours.color_ffffff,
child: Column(
children: <Widget>[
MyAppBar(
"消息中心",
showBack: false,
),
TabBar(
controller: tabController,
tabs: [
Tab(
child: SizedBox(
height: ScreenUtil().setWidth(60),
width: ScreenUtil().setWidth(144),
child: Stack(
children: [
Text(
"在线预订",
style: TextStyle(
color: tabController.index == 0
? selectedColor
: unSelectedColor,
fontSize: ScreenUtil().setSp(32),
fontWeight: FontWeight.bold),
),
Positioned(
top: 0,
right: 0,
child: Container(
width: ScreenUtil().setWidth(16),
height: ScreenUtil().setWidth(16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
ScreenUtil().setWidth(16)),
color: messageModel.onlineTotal > 0
? MyColours.color_fa5151
: MyColours.color_ffffff),
),
)
],
),
),
),
Tab(
child: SizedBox(
height: ScreenUtil().setWidth(60),
width: ScreenUtil().setWidth(144),
child: Stack(
children: [
Text(
"提前点餐",
style: TextStyle(
color: tabController.index == 1
? selectedColor
: unSelectedColor,
fontSize: ScreenUtil().setSp(32),
fontWeight: FontWeight.bold),
),
Positioned(
top: 0,
right: 0,
child: Container(
width: ScreenUtil().setWidth(16),
height: ScreenUtil().setWidth(16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
ScreenUtil().setWidth(16)),
color: messageModel.orderTotal > 0
? MyColours.color_fa5151
: MyColours.color_ffffff),
),
)
],
),
),
),
],
indicatorColor: MyColours.color_199095,
indicatorSize: TabBarIndicatorSize.label,
indicatorPadding: EdgeInsets.only(
left: ScreenUtil().setWidth(16),
right: ScreenUtil().setWidth(32)),
indicatorWeight: ScreenUtil().setWidth(6.0),
),
VEmptyView(11),
Expanded(
flex: 1,
child: TabBarView(
controller: tabController,
children: [MessageOnlinePage(), MessageOrderPage()]),
)
],
),
);
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
bus.off("refresh_untreated_num");
}
}