Commit 8d689f9d86c2d1e6479a30b8a58a25e092954a26

Authored by wdn127929
1 parent 00c1d080

菜品管理数据+UI

@@ -57,28 +57,28 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -57,28 +57,28 @@ class _MenuManagePageState extends State<MenuManagePage> {
57 }, 57 },
58 ), 58 ),
59 body: WillPopScope( 59 body: WillPopScope(
60 - onWillPop: () {  
61 - EventBus().emit('changeStatusColor');  
62 - Navigator.of(context).pop();  
63 - },  
64 - child: Column(  
65 - children: [  
66 - Expanded(child: Consumer<MenuManageProvider>(  
67 - builder: (context, model, _) {  
68 - if (model.pageState != PageState.Success) {  
69 - return ExceptionPage(  
70 - pageState: model.pageState,  
71 - callback: () {  
72 - // offset = 0;  
73 - // getMessage(showLoading: true);  
74 - // _couponNetworkData();  
75 - },  
76 - emptyMsg: "菜品是空哒,快点击分类管理添加分类和菜品吧",  
77 - emptyImg: "empty_search",  
78 - showMsg: "加载中,请稍后...",  
79 - );  
80 - } else {  
81 - return ListView.builder( 60 + onWillPop: () {
  61 + EventBus().emit('changeStatusColor');
  62 + Navigator.of(context).pop();
  63 + },
  64 + child: Consumer<MenuManageProvider>(
  65 + builder: (context, model, _) {
  66 + if (model.pageState != PageState.Success) {
  67 + return ExceptionPage(
  68 + pageState: model.pageState,
  69 + callback: () {
  70 + // offset = 0;
  71 + // getMessage(showLoading: true);
  72 + // _couponNetworkData();
  73 + },
  74 + emptyMsg: "菜品是空哒,快点击分类管理添加分类和菜品吧",
  75 + emptyImg: "empty_search",
  76 + showMsg: "加载中,请稍后...",
  77 + );
  78 + } else {
  79 + return Column(children: [
  80 + Expanded(
  81 + child: ListView.builder(
82 padding: EdgeInsets.symmetric( 82 padding: EdgeInsets.symmetric(
83 horizontal: ScreenUtil().setWidth(40), 83 horizontal: ScreenUtil().setWidth(40),
84 vertical: ScreenUtil().setWidth(40)), 84 vertical: ScreenUtil().setWidth(40)),
@@ -215,65 +215,68 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -215,65 +215,68 @@ class _MenuManagePageState extends State<MenuManagePage> {
215 // // getMessage(showLoading: false); 215 // // getMessage(showLoading: false);
216 // }, 216 // },
217 ); 217 );
218 - });  
219 - }  
220 - },  
221 - )),  
222 - // VEmptyView(20),  
223 - Row(  
224 - mainAxisAlignment: MainAxisAlignment.spaceBetween,  
225 - children: [  
226 - Padding(  
227 - padding: EdgeInsets.fromLTRB(  
228 - ScreenUtil().setWidth(40),  
229 - 0,  
230 - ScreenUtil().setWidth(40),  
231 - ScreenUtil().setWidth(40)),  
232 - child: RoundButton(  
233 - onPressed: () async {  
234 - bool needRefresh =  
235 - await NavigatorUtil.goCouponEditPage(context);  
236 - print(needRefresh);  
237 - if (needRefresh != null && needRefresh) {  
238 - //刷新页面数据  
239 - // _controller.callRefresh();  
240 - // _couponNetworkData();  
241 - }  
242 - },  
243 - text: '添加\n菜品',  
244 - fontSize: 26,  
245 - isBold: false,  
246 - height: ScreenUtil().setWidth(120),  
247 - width: ScreenUtil().setWidth(120),  
248 - radius: ScreenUtil().setWidth(60),  
249 - )),  
250 - Padding(  
251 - padding: EdgeInsets.fromLTRB(  
252 - ScreenUtil().setWidth(40),  
253 - 0,  
254 - ScreenUtil().setWidth(40),  
255 - ScreenUtil().setWidth(40)),  
256 - child: RoundButton(  
257 - onPressed: () async {  
258 - bool needRefresh =  
259 - await NavigatorUtil.goCouponEditPage(context);  
260 - print(needRefresh);  
261 - if (needRefresh != null && needRefresh) {  
262 - //刷新页面数据  
263 - // _controller.callRefresh();  
264 - // _couponNetworkData();  
265 - }  
266 - },  
267 - text: '分类\n管理',  
268 - fontSize: 26,  
269 - isBold: false,  
270 - height: ScreenUtil().setWidth(120),  
271 - width: ScreenUtil().setWidth(120),  
272 - radius: ScreenUtil().setWidth(60),  
273 - ))  
274 - ],  
275 - )  
276 - ],  
277 - ))); 218 + })),
  219 + Row(
  220 + mainAxisAlignment: MainAxisAlignment.spaceBetween,
  221 + children: [
  222 + model.pageState == PageState.Empty
  223 + ? SizedBox()
  224 + : Padding(
  225 + padding: EdgeInsets.fromLTRB(
  226 + ScreenUtil().setWidth(40),
  227 + 0,
  228 + ScreenUtil().setWidth(40),
  229 + ScreenUtil().setWidth(40)),
  230 + child: RoundButton(
  231 + onPressed: () async {
  232 + bool needRefresh =
  233 + await NavigatorUtil.goCouponEditPage(
  234 + context);
  235 + print(needRefresh);
  236 + if (needRefresh != null && needRefresh) {
  237 + //刷新页面数据
  238 + // _controller.callRefresh();
  239 + // _couponNetworkData();
  240 + }
  241 + },
  242 + text: '添加\n菜品',
  243 + fontSize: 26,
  244 + isBold: false,
  245 + height: ScreenUtil().setWidth(120),
  246 + width: ScreenUtil().setWidth(120),
  247 + radius: ScreenUtil().setWidth(60),
  248 + )),
  249 + Padding(
  250 + padding: EdgeInsets.fromLTRB(
  251 + ScreenUtil().setWidth(40),
  252 + 0,
  253 + ScreenUtil().setWidth(40),
  254 + ScreenUtil().setWidth(40)),
  255 + child: RoundButton(
  256 + onPressed: () async {
  257 + bool needRefresh =
  258 + await NavigatorUtil.goCouponEditPage(context);
  259 + print(needRefresh);
  260 + if (needRefresh != null && needRefresh) {
  261 + //刷新页面数据
  262 + // _controller.callRefresh();
  263 + // _couponNetworkData();
  264 + }
  265 + },
  266 + text: '分类\n管理',
  267 + fontSize: 26,
  268 + isBold: false,
  269 + height: ScreenUtil().setWidth(120),
  270 + width: ScreenUtil().setWidth(120),
  271 + radius: ScreenUtil().setWidth(60),
  272 + ))
  273 + ],
  274 + )
  275 + ]);
  276 + }
  277 + },
  278 + ),
  279 + // VEmptyView(20),
  280 + ));
278 } 281 }
279 } 282 }
1 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
2 import 'package:one_key/constant/constant.dart'; 2 import 'package:one_key/constant/constant.dart';
  3 +import 'package:one_key/constant/error.dart';
3 import 'package:one_key/constant/state.dart'; 4 import 'package:one_key/constant/state.dart';
4 import 'package:one_key/models/cookbook_model.dart'; 5 import 'package:one_key/models/cookbook_model.dart';
5 import 'package:one_key/net/base_resp.dart'; 6 import 'package:one_key/net/base_resp.dart';
@@ -8,7 +9,7 @@ import 'package:one_key/net/http_url.dart'; @@ -8,7 +9,7 @@ import 'package:one_key/net/http_url.dart';
8 import 'package:one_key/utils/utils.dart'; 9 import 'package:one_key/utils/utils.dart';
9 10
10 class MenuManageProvider extends ChangeNotifier { 11 class MenuManageProvider extends ChangeNotifier {
11 - PageState pageState = PageState.Success; 12 + PageState pageState = PageState.Loading;
12 List<MenuModel> menuModel; //菜品数据 13 List<MenuModel> menuModel; //菜品数据
13 14
14 ///分类下所有菜品列表(1.传orderid顾客端获取带订单信息的 否则不传 15 ///分类下所有菜品列表(1.传orderid顾客端获取带订单信息的 否则不传
@@ -19,18 +20,38 @@ class MenuManageProvider extends ChangeNotifier { @@ -19,18 +20,38 @@ class MenuManageProvider extends ChangeNotifier {
19 data: params, showLoading: false) 20 data: params, showLoading: false)
20 .catchError((error) { 21 .catchError((error) {
21 print(error.toString()); 22 print(error.toString());
  23 + if (error is MyError) {
  24 + switch (error.type) {
  25 + case 1:
  26 + pageState = PageState.ConnectivityError;
  27 + break;
  28 + case 2:
  29 + pageState = PageState.ConnectivityTimeOut;
  30 + break;
  31 + default:
  32 + pageState = PageState.ConnectivityError;
  33 + break;
  34 + }
  35 + }
  36 + notifyListeners();
22 }); 37 });
23 menuModel = []; 38 menuModel = [];
24 39
25 if (baseResp != null && baseResp.code == Constant.status_success) { 40 if (baseResp != null && baseResp.code == Constant.status_success) {
26 - List menu = baseResp.data[0]['list'];  
27 - for (int i = 0; i < menu.length; i++) {  
28 - menuModel.add(MenuModel.fromJson(menu[i])); 41 + if (baseResp.data[0]['list'] == '') {
  42 + pageState = PageState.Empty;
  43 + } else {
  44 + List menu = baseResp.data[0]['list'];
  45 + for (int i = 0; i < menu.length; i++) {
  46 + menuModel.add(MenuModel.fromJson(menu[i]));
  47 + }
  48 + print(menuModel);
  49 + pageState = PageState.Success;
29 } 50 }
30 - print(menuModel);  
31 - notifyListeners();  
32 } else { 51 } else {
33 Utils.showToast(baseResp.msg ?? ""); 52 Utils.showToast(baseResp.msg ?? "");
  53 + pageState = PageState.ConnectivityError;
34 } 54 }
  55 + notifyListeners();
35 } 56 }
36 } 57 }