Commit 744f2ec57f5459b206fe72a409b1d089611ca116

Authored by wdn127929
1 parent 5d128518

向上、向下移动、大小图、菜单名称样式

import 'package:flutter/material.dart';
import 'package:one_key/models/radio_model.dart';
import 'package:one_key/utils/utils.dart';
///菜单
... ... @@ -116,6 +117,53 @@ class MenuSunModel {
String nameType = '3'; //1左侧,2右侧,3顶部分开
String imageType = '1'; //1大图,2小图
int sort;
int indexNew;
//名称样式选择数组
List<RadioModel> get nameTypeList {
RadioModel radioModel1 = RadioModel();
radioModel1.title = '菜品名称(味型/烹调)及价格在顶部左侧';
radioModel1.code = '1';
radioModel1.select = nameType == radioModel1.code ? true : false;
RadioModel radioModel2 = RadioModel();
radioModel2.title = '菜品名称(味型/烹调)及价格在顶部右侧';
radioModel2.code = '2';
radioModel2.select = nameType == radioModel2.code ? true : false;
RadioModel radioModel3 = RadioModel();
radioModel3.title = '菜品名称(味型/烹调)及价格在顶部分开';
radioModel3.code = '3';
radioModel3.select = nameType == radioModel3.code ? true : false;
return [radioModel1, radioModel2, radioModel3];
}
//图片样式选择数组
List<RadioModel> get imageTypeList {
RadioModel radioModel1 = RadioModel();
radioModel1.title = '大图展示菜品';
radioModel1.code = '1';
radioModel1.select = imageType == radioModel1.code ? true : false;
RadioModel radioModel2 = RadioModel();
radioModel2.title = '小图展示菜品';
radioModel2.code = '2';
radioModel2.select = imageType == radioModel2.code ? true : false;
return [radioModel1, radioModel2];
}
//图片移动数组
List<RadioModel> get moveList {
RadioModel radioModel1 = RadioModel();
radioModel1.title = '菜品向上移动一个';
radioModel1.code = '1';
radioModel1.select = false;
RadioModel radioModel2 = RadioModel();
radioModel2.title = '菜品向下移动一个';
radioModel2.code = '2';
radioModel2.select = false;
return [radioModel1, radioModel2];
}
MenuSunModel(
{this.id,
... ... @@ -149,7 +197,8 @@ class MenuSunModel {
this.cookList,
this.amountC,
this.nameType,
this.imageType});
this.imageType,
this.sort});
MenuSunModel.fromJson(Map<String, dynamic> json) {
id = json['id'];
... ... @@ -188,8 +237,10 @@ class MenuSunModel {
}
// imageType = Utils.randomGet(1, 3) ?? '1';
// nameType = Utils.randomGet(1, 4) ?? '3';
imageType = name == '小炒肉' || name == '水煮肉片' || name == '西湖牛肉羹'? '2' : '1';
imageType = name == '小炒肉' || name == '水煮肉片' || name == '西湖牛肉羹' ? '2' : '1';
nameType = '1';
sort = json['sort'];
}
MenuSunModel.fromJson3(Map<String, dynamic> json) {
... ... @@ -297,6 +348,7 @@ class MenuSunModel {
data['practice'] = this.practice;
data['amount'] = this.amount;
data['cookList'] = this.cookList;
data['sort'] = this.sort;
return data;
}
}
... ...
class RadioModel {
String title;
bool select;
String code;
}
... ...
... ... @@ -88,11 +88,25 @@ class _MenuManagePageState extends State<MenuManagePage> {
await menuManageProvider.getCookbookByClass(context, params,
showLoading: showLoading);
_handleData();
}
///处理数据
_handleData({isMove = false}) {
if (menuManageProvider.menuModel != null) {
List<MenuModel> temp = [];
for (int i = 0; i < menuManageProvider.menuModel.length; i++) {
List<dynamic> listSub = [];
// if (menuManageProvider.menuModel[i].cookbooklist.length > 0 &&
// menuManageProvider.menuModel[i].cookbooklist[0].indexNew == null &&
// !isMove) {
// //没有设置过顺序
// for (int j = 0;
// j < menuManageProvider.menuModel[i].cookbooklist.length;
// j++) {
// menuManageProvider.menuModel[i].cookbooklist[j].indexNew = j; //初始化菜单顺序
// }
// }
for (int j = 0;
j < menuManageProvider.menuModel[i].cookbooklist.length;
j++) {
... ... @@ -100,6 +114,7 @@ class _MenuManagePageState extends State<MenuManagePage> {
menuManageProvider.menuModel[i].cookbooklist[j];
if (menuSunModel.imageType == '1') {
//大图
menuSunModel.indexNew = j;
listSub.add(menuSunModel);
} else {
//小图
... ... @@ -109,18 +124,23 @@ class _MenuManagePageState extends State<MenuManagePage> {
.menuModel[i].cookbooklist[j + 1].imageType ==
'1') {
//下一个是大图
menuSunModel.indexNew = j;
listSub.add(menuSunModel);
} else {
//下一个是小图
List<MenuSunModel> subTemp = [];
menuSunModel.indexNew = j;
subTemp.add(menuSunModel);
menuManageProvider.menuModel[i].cookbooklist[j + 1].indexNew =
j + 1;
subTemp
.add(menuManageProvider.menuModel[i].cookbooklist[j + 1]);
listSub.add(subTemp);
j++;
}
} else {
menuSunModel.indexNew = j;
listSub.add(menuSunModel);
}
}
... ... @@ -130,6 +150,7 @@ class _MenuManagePageState extends State<MenuManagePage> {
}
menuManageProvider.menuModel = temp;
setState(() {});
}
}
//左边
... ... @@ -355,6 +376,50 @@ class _MenuManagePageState extends State<MenuManagePage> {
);
}
_onLongPress(MenuSunModel model, int indexOut) async {
Map object = await DialogUtil.menuMagageAlertDialog(
context, model.nameTypeList, model.imageTypeList, model.moveList);
if (object != null) {
print(object);
if (object['name_type'] != null) {
//有一个选中
model.nameType = object['name_type'];
} else {
//全部不选择
model.nameType = null;
}
if (object['image_type'] != null) {
model.imageType = object['image_type'];
} else {
model.imageType = null;
}
if (object['move'] != null) {
if (object['move'] == '1') {
//向上移动
var child = menuManageProvider.menuModel[indexOut].cookbooklist
.removeAt(model.indexNew);
menuManageProvider.menuModel[indexOut].cookbooklist
.insert(model.indexNew - 1, child);
_handleData(isMove: true);
} else if (object['move'] == '2') {
//向下移动
var child = menuManageProvider.menuModel[indexOut].cookbooklist
.removeAt(model.indexNew);
menuManageProvider.menuModel[indexOut].cookbooklist
.insert(model.indexNew + 1, child);
_handleData(isMove: true);
}
}
}
;
}
@override
Widget build(BuildContext context) {
menuManageProvider = Provider.of<MenuManageProvider>(context, listen: true);
... ... @@ -544,15 +609,8 @@ class _MenuManagePageState extends State<MenuManagePage> {
return GestureDetector(
onLongPress: () async {
print('onLongPress 长按事件');
Map object = await DialogUtil
.menuMagageAlertDialog(
context);
if (object != null) {
print(object);
// 'name_type':'1',
// 'image_type':'1',
// 'move':'1'
}
_onLongPress(model, indexOut);
},
child: Stack(
children: [
... ... @@ -580,6 +638,7 @@ class _MenuManagePageState extends State<MenuManagePage> {
return GestureDetector(
onLongPress: () {
print('onLongPress 长按事件');
_onLongPress(model, indexOut);
},
child: Stack(children: [
Container(
... ... @@ -704,6 +763,8 @@ class _MenuManagePageState extends State<MenuManagePage> {
onLongPress: () {
print(
'onLongPress 长按事件');
_onLongPress(temp[0],
indexOut);
},
child: Stack(
children: [
... ... @@ -736,6 +797,9 @@ class _MenuManagePageState extends State<MenuManagePage> {
onLongPress: () {
print(
'onLongPress 长按事件');
_onLongPress(temp[1],
indexOut);
},
child: Stack(
children: [
... ...
... ... @@ -36,6 +36,7 @@ import 'package:table_calendar/table_calendar.dart';
import 'package:one_key/models/table.dart' as t;
import 'package:url_launcher/url_launcher.dart';
import '../models/radio_model.dart';
import '../models/theme_color_model.dart';
typedef CustomCallBack = void Function(Object object);
... ... @@ -53,14 +54,19 @@ typedef ClickCallback = void Function(String value);
// };
class DialogUtil {
static Future menuMagageAlertDialog(BuildContext context,
{GestureTapCallback onTap, double fontSize = 32}) async {
static Future menuMagageAlertDialog(
BuildContext context,
List<RadioModel> nameTypeList,
List<RadioModel> imageTypeList,
List<RadioModel> moveList,
{GestureTapCallback onTap,
double fontSize = 32}) async {
final action = await showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return Center(
child: Container(
return Center(child: StatefulBuilder(builder: (context, state) {
return Container(
padding:
EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)),
decoration: BoxDecoration(
... ... @@ -71,68 +77,138 @@ class DialogUtil {
Radius.circular(ScreenUtil().setWidth(30)))), //设置圆角
child: Column(mainAxisSize: MainAxisSize.min, children: [
VEmptyView(92),
Container(
height: ScreenUtil().setWidth(96),
alignment: Alignment.center,
child: Text('菜品名称(味型/烹调)及价格在顶部左侧',
style: TextStyle(
fontSize: ScreenUtil().setSp(fontSize),
color: MyColours.color_515151)),
),
Container(
height: ScreenUtil().setWidth(96),
alignment: Alignment.center,
child: Text('菜品名称(味型/烹调)及价格在顶部右侧',
style: TextStyle(
fontSize: ScreenUtil().setSp(fontSize),
color: MyColours.color_515151)),
),
Container(
height: ScreenUtil().setWidth(96),
alignment: Alignment.center,
child: Text('菜品名称(味型/烹调)及价格在顶部分开',
style: TextStyle(
fontSize: ScreenUtil().setSp(fontSize),
color: MyColours.color_515151)),
),
ListView.builder(
itemCount: nameTypeList.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
if (imageTypeList.length > 1 &&
imageTypeList[1].select) {
return;
} else {
nameTypeList.forEach((element) {
element.select = false;
});
nameTypeList[index].select = true;
state(() {});
}
},
child: Container(
height: ScreenUtil().setWidth(96),
alignment: Alignment.center,
child: Text(nameTypeList[index].title,
style: TextStyle(
fontSize: ScreenUtil().setSp(fontSize),
color: imageTypeList.length > 1 &&
imageTypeList[1].select
? MyColours.color_999999
: nameTypeList[index].select
? MyColours.color_438E93
: MyColours.color_515151)),
));
}),
// Container(
// height: ScreenUtil().setWidth(96),
// alignment: Alignment.center,
// child: Text('菜品名称(味型/烹调)及价格在顶部右侧',
// style: TextStyle(
// fontSize: ScreenUtil().setSp(fontSize),
// color: MyColours.color_515151)),
// ),
// Container(
// height: ScreenUtil().setWidth(96),
// alignment: Alignment.center,
// child: Text('菜品名称(味型/烹调)及价格在顶部分开',
// style: TextStyle(
// fontSize: ScreenUtil().setSp(fontSize),
// color: MyColours.color_515151)),
// ),
MyDivider(
ScreenUtil().setWidth(280 * 2), ScreenUtil().setWidth(2),
color: MyColours.color_efefef),
Container(
height: ScreenUtil().setWidth(96),
alignment: Alignment.center,
child: Text('大图展示菜品',
style: TextStyle(
fontSize: ScreenUtil().setSp(fontSize),
color: MyColours.color_515151)),
),
Container(
height: ScreenUtil().setWidth(96),
alignment: Alignment.center,
child: Text('小图展示菜品',
style: TextStyle(
fontSize: ScreenUtil().setSp(fontSize),
color: MyColours.color_515151)),
),
ListView.builder(
itemCount: imageTypeList.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
imageTypeList.forEach((element) {
element.select = false;
});
imageTypeList[index].select = true;
state(() {});
},
child: Container(
height: ScreenUtil().setWidth(96),
alignment: Alignment.center,
child: Text(imageTypeList[index].title,
style: TextStyle(
fontSize: ScreenUtil().setSp(fontSize),
color: imageTypeList[index].select
? MyColours.color_438E93
: MyColours.color_515151)),
));
}),
// Container(
// height: ScreenUtil().setWidth(96),
// alignment: Alignment.center,
// child: Text('大图展示菜品',
// style: TextStyle(
// fontSize: ScreenUtil().setSp(fontSize),
// color: MyColours.color_515151)),
// ),
// Container(
// height: ScreenUtil().setWidth(96),
// alignment: Alignment.center,
// child: Text('小图展示菜品',
// style: TextStyle(
// fontSize: ScreenUtil().setSp(fontSize),
// color: MyColours.color_515151)),
// ),
MyDivider(
ScreenUtil().setWidth(280 * 2), ScreenUtil().setWidth(2),
color: MyColours.color_efefef),
Container(
height: ScreenUtil().setWidth(96),
alignment: Alignment.center,
child: Text('菜品向上移动一个',
style: TextStyle(
fontSize: ScreenUtil().setSp(fontSize),
color: MyColours.color_515151)),
),
Container(
height: ScreenUtil().setWidth(96),
alignment: Alignment.center,
child: Text('菜品向下移动一个',
style: TextStyle(
fontSize: ScreenUtil().setSp(fontSize),
color: MyColours.color_515151)),
),
ListView.builder(
itemCount: moveList.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
moveList.forEach((element) {
element.select = false;
});
moveList[index].select = true;
state(() {});
},
child: Container(
height: ScreenUtil().setWidth(96),
alignment: Alignment.center,
child: Text(moveList[index].title,
style: TextStyle(
fontSize: ScreenUtil().setSp(fontSize),
color: moveList[index].select
? MyColours.color_438E93
: MyColours.color_515151)),
));
}),
// Container(
// height: ScreenUtil().setWidth(96),
// alignment: Alignment.center,
// child: Text('菜品向上移动一个',
// style: TextStyle(
// fontSize: ScreenUtil().setSp(fontSize),
// color: MyColours.color_515151)),
// ),
// Container(
// height: ScreenUtil().setWidth(96),
// alignment: Alignment.center,
// child: Text('菜品向下移动一个',
// style: TextStyle(
// fontSize: ScreenUtil().setSp(fontSize),
// color: MyColours.color_515151)),
// ),
VEmptyView(60),
MyDivider(double.infinity, ScreenUtil().setWidth(2),
color: MyColours.color_f3f3f3),
... ... @@ -175,18 +251,37 @@ class DialogUtil {
// return;
// }
// onTap(controller.text);
List<RadioModel> nameSelect = nameTypeList
.where((element) => element.select)
.toList();
List<RadioModel> imageSelect = imageTypeList
.where((element) => element.select)
.toList();
List<RadioModel> moveSelect = moveList
.where((element) => element.select)
.toList();
Navigator.pop(context, {
'name_type': '1',
'image_type': '1',
'move': '1'
'name_type':
nameSelect != null && nameSelect.length > 0
? nameSelect[0].code
: null,
'image_type':
imageSelect != null && imageSelect.length > 0
? imageSelect[0].code
: null,
'move':
moveSelect != null && moveSelect.length > 0
? moveSelect[0].code
: null,
});
// }
}),
],
),
])),
),
);
);
}));
},
);
return action;
... ...