plan_dish_provider.dart
2.17 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
import 'package:flutter/material.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/net/base_resp.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/utils/utils.dart';
import '../constant/constant.dart';
import '../constant/error.dart';
import '../models/cookbook_model.dart';
import '../net/http_url.dart';
/**
* 预排菜
*/
class PlanDishProvider extends ChangeNotifier {
PageState pageState = PageState.Success;
PageState pageStateStore = PageState.Success;
PageState pageStateMine = PageState.Success;
PageState pageStateMy = PageState.Success;
List<MenuModel> menuModel; //菜品数据
// List<CookbookCategorySunModel> categorySunModel; //菜品分类数据
// List<CookbookSpecSunModel> specSunModel; //计价单位
// CookbookOneSunModel cookbookOneSunModel;
///分类下所有菜品列表(1.传orderid顾客端获取带订单信息的 否则不传
getCookbookByClass(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.get_cookbook_by_class,
data: params, showLoading: showLoading)
.catchError((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();
});
menuModel = [];
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data[0]['list'] == '') {
pageState = PageState.Empty;
} else {
List menu = baseResp.data[0]['list'];
for (int i = 0; i < menu.length; i++) {
menuModel.add(MenuModel.fromJson(menu[i]));
}
print(menuModel);
pageState = PageState.Success;
}
} else {
Utils.showToast(baseResp.msg ?? "");
pageState = PageState.ConnectivityError;
}
notifyListeners();
}
}