remark_manager_page.dart
13.7 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/models/remark.dart';
import 'package:one_key/provider/remark_manager_model.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/MyDivider.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/page_exception.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';
import '../../app.dart';
class RemarkManagerPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return RemarkManagerPageState();
}
}
class RemarkManagerPageState extends State<RemarkManagerPage> {
RemarkManagerModel remarkManagerModel;
bool isAdding = false; //正在添加备注
TextEditingController _controller = TextEditingController();
FocusNode focusNode = FocusNode();
int alwaysCount = 0; //常用备注数
@override
void initState() {
// TODO: implement initState
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
_getRemarks(showPageLoading: true);
});
}
//获取备注
_getRemarks({bool showPageLoading = false}) {
Map<String, String> params = {
"uid": Provider.of<UserModel>(context, listen: false).user.openid
};
remarkManagerModel.getRemarks(context, params,
showPageLoading: showPageLoading);
}
//添加备注
_addRemark() async {
Map<String, String> params = {
"uid": Provider.of<UserModel>(context, listen: false).user.openid,
"custom": _controller.text
};
await remarkManagerModel.addRemark(context, params);
_getRemarks(showPageLoading: false); //添加完重新获取备注信息
}
//添加常用备注
_addCustomRemark(Remark remark) {
Map<String, String> params = {
"uid": Provider.of<UserModel>(context, listen: false).user.openid,
"kid": remark.id,
"flag": "custom"
};
remarkManagerModel.getRemarks(context, params);
}
//取消常用备注
_delCustomRemark(Remark remark) {
if (remark.id == "-1") return;
Map<String, String> params = {
"uid": Provider.of<UserModel>(context, listen: false).user.openid,
"kid": remark.id,
"flag": "often"
};
remarkManagerModel.getRemarks(context, params);
}
//构建常用备注
List<Widget> _buildAlwayItems() {
List<Widget> always = [];
for (Remark remark in remarkManagerModel.remarks) {
if (remark.oftenUse != null && remark.oftenUse.isNotEmpty)
always.add(Container(
height: ScreenUtil().setWidth(50),
decoration: BoxDecoration(
color: MyColours.color_199095,
borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10))),
child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Flexible(
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)),
child: Text(
"${remark.oftenUse}",
style: TextStyle(
fontSize: ScreenUtil().setSp(30),
color: MyColours.color_ffffff,
),
overflow: TextOverflow.ellipsis,
),
),
),
MyDivider(
ScreenUtil().setWidth(2),
ScreenUtil().setWidth(30),
color: MyColours.color_6AB6B9,
),
GestureDetector(
onTap: () {
setState(() {
remark.oftenUse = "";
});
_delCustomRemark(remark);
},
child: Padding(
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
child: Image.asset(
"assets/icon_remark_del.png",
width: ScreenUtil().setWidth(18),
height: ScreenUtil().setWidth(18),
),
))
]),
));
}
alwaysCount = always.length;
return always;
}
//构建所有备注
List<Widget> _buildAllItems() {
List<Widget> alls = [];
for (Remark remark in remarkManagerModel.remarks) {
alls.add(
GestureDetector(
onTap: () {
if (alwaysCount >= 10) {
Utils.showToast("最多添加10个常用备注");
return;
}
setState(() {
remark.oftenUse = remark.custom;
_addCustomRemark(remark);
});
},
child: Container(
height: ScreenUtil().setWidth(50),
padding:
EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)),
decoration:
(remark.oftenUse != null && remark.oftenUse.isNotEmpty)
? BoxDecoration(
color: MyColours.color_199095,
borderRadius:
BorderRadius.circular(ScreenUtil().setWidth(10)))
: BoxDecoration(
color: MyColours.color_ffffff,
borderRadius:
BorderRadius.circular(ScreenUtil().setWidth(10)),
border: Border.all(
color: MyColours.color_6AB6B9,
width: ScreenUtil().setWidth(2))),
child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Flexible(
child: Text(
"${remark.custom}",
style: TextStyle(
fontSize: ScreenUtil().setSp(30),
color:
(remark.oftenUse != null && remark.oftenUse.isNotEmpty)
? MyColours.color_ffffff
: MyColours.color_199095,
),
overflow: TextOverflow.ellipsis,
)),
]),
)),
);
}
alls.add(Stack(
children: [
isAdding
? Container(
width: ScreenUtil().setWidth(200),
height: ScreenUtil().setWidth(50),
alignment: Alignment.center,
padding:
EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)),
decoration: BoxDecoration(
border: Border.all(
color: MyColours.color_cccccc,
width: ScreenUtil().setWidth(2)),
borderRadius:
BorderRadius.circular(ScreenUtil().setWidth(10))),
child: TextField(
controller: _controller,
focusNode: focusNode,
autofocus: true,
textInputAction: TextInputAction.done,
textAlignVertical: TextAlignVertical.center,
keyboardType: TextInputType.text,
decoration: InputDecoration.collapsed(hintText: ""),
inputFormatters: [LengthLimitingTextInputFormatter(10)],
style: TextStyle(
color: MyColours.color_353535,
fontSize: ScreenUtil().setSp(30),
textBaseline: TextBaseline.alphabetic),
onEditingComplete: () {
if (_controller.text.isEmpty) {
setState(() {
isAdding = false;
return;
});
}
setState(() {
isAdding = false;
});
_addRemark();
_controller.clear();
},
))
: GestureDetector(
onTap: () {
if (remarkManagerModel.remarks.length >= 20) {
Utils.showToast("最多添加20个备注");
return;
}
if (alwaysCount >= 10) {
Utils.showToast("最多添加10个常用备注");
return;
}
setState(() {
isAdding = true;
});
},
child: Container(
width: ScreenUtil().setWidth(200),
height: ScreenUtil().setWidth(50),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(
color: MyColours.color_cccccc,
width: ScreenUtil().setWidth(2)),
borderRadius:
BorderRadius.circular(ScreenUtil().setWidth(10))),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset(
"assets/icon_remark_add.png",
width: ScreenUtil().setWidth(30),
height: ScreenUtil().setWidth(30),
),
HEmptyView(10),
Text(
"添加备注",
style: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(30)),
)
],
),
),
)
],
));
return alls;
}
@override
Widget build(BuildContext context) {
// TODO: implement build
remarkManagerModel =
Provider.of<RemarkManagerModel>(context, listen: false);
return Scaffold(
backgroundColor: MyColours.color_ffffff,
appBar: SystemAppBar(
'常用备注管理',
onTap: () {
Navigator.of(context).pop();
},
),
body: SafeArea(
child: Consumer<RemarkManagerModel>(
builder: (context, model, _) {
if (model.pageState != PageState.Success) {
return ExceptionPage(
pageState: model.pageState,
callback: () {
_getRemarks(showPageLoading: true);
},
emptyMsg: "暂时没有备注哦",
emptyImg: "empty_search",
showMsg: "加载中,请稍后...",
);
} else {
return Container(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(40)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
VEmptyView(60),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"我的常用备注",
style: TextStyle(
color: MyColours.color_353535,
fontSize: ScreenUtil().setSp(30),
fontWeight: FontWeight.bold),
),
Text(
"(最多添加10个)",
style: TextStyle(
color: MyColours.color_666666,
fontSize: ScreenUtil().setSp(26)),
),
],
),
Padding(
padding: EdgeInsets.symmetric(
vertical: ScreenUtil().setWidth(40)),
child: Wrap(
spacing: ScreenUtil().setWidth(20),
runSpacing: ScreenUtil().setWidth(20),
children: _buildAlwayItems()),
),
MyDivider(
double.infinity,
ScreenUtil().setWidth(2),
color: MyColours.color_f3f3f3,
),
VEmptyView(40),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"所有备注",
style: TextStyle(
color: MyColours.color_353535,
fontSize: ScreenUtil().setSp(30),
fontWeight: FontWeight.bold),
),
Text(
"(最多添加20个)",
style: TextStyle(
color: MyColours.color_666666,
fontSize: ScreenUtil().setSp(26)),
),
],
),
Padding(
padding: EdgeInsets.symmetric(
vertical: ScreenUtil().setWidth(40)),
child: Wrap(
spacing: ScreenUtil().setWidth(20),
runSpacing: ScreenUtil().setWidth(20),
children: _buildAllItems()),
)
],
),
);
}
},
),
));
}
}