remark_manager_model.dart
2.76 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
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:one_key/constant/constant.dart';
import 'package:one_key/constant/error.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/models/remark.dart';
import 'package:one_key/net/base_resp.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/net/http_url.dart';
/**
* 常用备注管理
*/
class RemarkManagerModel extends ChangeNotifier {
List<Remark> remarks = []; //所有备注
List<Remark?> ofenRemarks = []; //常用备注
PageState pageState = PageState.Loading;
//获取备注
getRemarks(BuildContext context, Map<String, String?> params,
{bool showPageLoading = false, bool selfDismiss = false}) async {
if (showPageLoading) {
pageState = PageState.Loading;
notifyListeners();
}
try {
BaseResp<List?> baseResp = await DioUtil().request<List>(
context, Method.post, HttpUrl.get_custom_remark,
data: params,
showLoading: showPageLoading ? false : true,
selfDismiss: selfDismiss);
if (baseResp != null && baseResp.code == Constant.status_success) {
remarks = baseResp.data!.map<Remark>((value) {
return Remark.fromJson(value);
}).toList();
ofenRemarks = [];
for (Remark item in remarks) {
if (item.oftenUse != '') {
ofenRemarks.add(item);
}
}
if (remarks.isEmpty) {
pageState = PageState.Empty;
} else {
pageState = PageState.Success;
}
notifyListeners();
}
} catch (error) {
print(error.toString());
if (error is MyError) {
switch (error.type) {
case 1:
pageState = PageState.ConnectivityError;
break;
case 2:
pageState = PageState.ConnectivityTimeOut;
break;
default:
pageState = PageState.ConnectivityError;
break;
}
}
notifyListeners();
}
}
//添加备注
Future addRemark(BuildContext context, Map<String, String?> params) async {
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.post, HttpUrl.add_custom_remark,
data: params, showLoading: false);
} catch (error) {
print(error.toString());
}
return;
}
//删除备注
delRemark(BuildContext context, Map<String, String> params) async {
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.post, HttpUrl.del_custom_remark,
data: params, showLoading: false);
if (baseResp != null && baseResp.code == Constant.status_success) {}
} catch (error) {
print(error.toString());
}
}
}