feast_dish_page.dart 10.2 KB
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/widgets/v_empty_view.dart';

import '../../../res/colors.dart';
import '../../../utils/dialog_util.dart';
import '../../../utils/screen_util.dart';
import '../../../utils/utils.dart';
import '../../../widgets/h_empty_view.dart';
import '../../../widgets/round_button.dart';
import '../../../widgets/system_app_bar.dart';

/**
 * 菜品
 */

class FeastDishPage extends StatefulWidget {
  FeastDishPage({Key key}) : super(key: key);

  @override
  _FeastDishPageState createState() => _FeastDishPageState();
}

class _FeastDishPageState extends State<FeastDishPage> {
  ScrollController controller = ScrollController();
  TextEditingController typeNameC = TextEditingController(); //分类名称
  FocusNode typeF = FocusNode();
  @override
  void initState() {
    super.initState();
    Utils.changeStatusColor(color: MyColours.color_438E93);
  }

  Widget buildFeastTypeHeader() {
    return RoundButton(
      onPressed: () async {
        NavigatorUtil.goFeastSetmealManageEditPage(context);
      },
      text: '添加一项',
      fontSize: 32,
      isBold: false,
      height: h(32),
      width: w(80),
      margin: EdgeInsets.only(top: w(18), bottom: w(4)),
      textColor: MyColours.color_438E93,
      gradientStart: MyColours.color_ffffff,
      gradientEnd: MyColours.color_ffffff,
      borderColor: MyColours.color_438E93,
      radius: r(6),
    );
  }

  Widget buildFeastTypeItem() {
    return Container(
      margin: EdgeInsets.only(bottom: w(12)),
      child: Row(
        children: [
          Container(
              width: w(120),
              child: Text(
                '鱼香肉丝',
                style: TextStyle(
                    fontSize: font(16), color: MyColours.color_E6000000),
              )),
          HEmptyView(16),
          Container(
              width: w(36),
              child: Text(
                '份',
                style: TextStyle(
                    fontSize: font(16), color: MyColours.color_515151),
              )),
          HEmptyView(16),
          Container(
              width: w(80),
              child: Text(
                '可调菜/不可调菜',
                style: TextStyle(
                    fontSize: font(16),
                    color:
                        true ? MyColours.color_00A870 : MyColours.color_E34D59),
              )),
          Spacer(),
          InkWell(
              onTap: () {
                FocusScope.of(context).requestFocus(FocusNode());
                DialogUtil.feastDishEditDialog(context, onTap: (Map map) {
                  String per = map['per'];
                  String name = map['name'];
                  String can = map['can'];
                  print(can);
                });
              },
              child: Text(
                '修改',
                style: TextStyle(
                    decoration: TextDecoration.underline,
                    fontSize: font(16),
                    color: MyColours.color_438E93),
              )),
          HEmptyView(24),
          InkWell(
              onTap: () {
                //已经传到服务器,弹提醒窗口,是否删除
                //修改之前有内容,则弹框
                DialogUtil.cupertinoAlertDialogFeast(context,
                    rTitle: '删除',
                    title: "是否确认删除",
                    content: "鱼香肉丝", lCallback: () {
                  print("取消");
                }, rCallback: () {
                  print("确定");
                  // widget.deleteCallback(index);
                });
              },
              child: Image.asset(
                Utils.getImgPath(true ? 'f_delete_red_un' : 'f_delete_red'),
                width: w(24),
                height: w(24),
              )),
          HEmptyView(24),
        ],
      ),
    );
  }

  Widget _textfield(
      String title,
      String hintText,
      TextEditingController editingController,
      FocusNode focusNode,
      String subTitle,
      {TextInputType inputType = TextInputType.number}) {
    return Container(
      height: w(48),
      margin: EdgeInsets.only(top: w(12)),
      decoration: BoxDecoration(
          border: Border(
              bottom:
                  BorderSide(width: h(0.5), color: MyColours.color_E7E7E7))),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            width: w(81),
            height: w(48),
            alignment: Alignment.center,
            child: Text(
              title,
              style: TextStyle(
                  fontSize: ScreenUtil().setSp(32),
                  color: MyColours.color_E5000000),
            ),
          ),
          HEmptyView(32),
          Expanded(
            child: Container(
                // height: ScreenUtil().setHeight(120),
                height: w(48),
                padding: EdgeInsets.only(top: w(4)),
                child: TextField(
                  controller: editingController,
                  // textAlign: TextAlign.right,
                  // textAlignVertical: TextAlignVertical.bottom,
                  maxLines: 1,
                  inputFormatters: [],

                  // //光标颜色
                  // cursorColor:
                  //     widget.isSelect ? Colors.white : MyColours.color_199095,
                  //输入文本的样式
                  style: TextStyle(
                      fontSize: ScreenUtil().setSp(32),
                      color: MyColours.color_515151),
                  focusNode: focusNode,
                  decoration: InputDecoration(
                    border: OutlineInputBorder(borderSide: BorderSide.none),
                    hintText: hintText,
                    hintStyle: TextStyle(
                      color: hintText == '请输入'
                          ? MyColours.color_999999
                          : MyColours.color_515151,
                      fontSize: ScreenUtil().setSp(32),
                    ),
                    contentPadding: EdgeInsets.zero,
                  ),
                  onChanged: (value) {
                    typeNameC.text = value;
                    setState(() {});
                  },
                  onEditingComplete: () {
                    FocusScope.of(context)
                        .requestFocus(FocusNode()); //点击空白处隐藏键盘
                  },
                  keyboardType: inputType,
                )),
          ),
          HEmptyView(24)
          // Spacer(),
          // Container(
          //   padding: EdgeInsets.only(left: w(16), right: w(12)),
          //   child: Text(
          //     subTitle,
          //     style: TextStyle(
          //         color: MyColours.color_000000,
          //         fontSize: ScreenUtil().setSp(32)),
          //   ),
          // ),
        ],
      ),
    );
  }

  Widget _callButton(
      {GestureTapCallback onPress,
      content,
      hasLeftBorder = true,
      isSelect = false}) {
    return InkWell(
      onTap: onPress,
      child: Container(
        height: h(48),
        decoration: BoxDecoration(
            color: isSelect ? MyColours.color_438E93 : MyColours.color_ffffff,
            border: Border(
                bottom: BorderSide(
                    color: MyColours.color_438E93,
                    width: ScreenUtil().setWidth(2)),
                top: BorderSide(
                    color: MyColours.color_438E93,
                    width: ScreenUtil().setWidth(2)),
                left: hasLeftBorder
                    ? BorderSide(
                        color: MyColours.color_438E93,
                        width: ScreenUtil().setWidth(2))
                    : BorderSide.none,
                right: BorderSide(
                    color: MyColours.color_438E93,
                    width: ScreenUtil().setWidth(2)))),
        child: Align(
          alignment: Alignment.center,
          child: Text(
            content,
            style: TextStyle(
                color:
                    isSelect ? MyColours.color_F6F6F6 : MyColours.color_438E93,
                fontSize: ScreenUtil().setSp(36)),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: MyColours.color_ffffff,
        appBar: SystemAppBar(
          typeNameC.text,
          needWhite: true,
          bgColor: MyColours.color_438E93,
          titleColor: MyColours.color_F6F6F6,
          onTap: () {
            Navigator.pop(context);
          },
        ),
        body: Column(
          children: [
            Expanded(
                child: SingleChildScrollView(
              controller: controller,
              child: Padding(
                  padding: EdgeInsets.only(left: w(16)),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      _textfield('分类名称', '热菜', typeNameC, typeF, ''),
                      buildFeastTypeHeader(),
                      VEmptyView(54),
                      ListView.builder(
                          itemCount: 100,
                          shrinkWrap: true,
                          controller: controller,
                          itemBuilder: (BuildContext context, int index) {
                            return buildFeastTypeItem();
                          }),
                    ],
                  )),
            )),
            Row(
              children: [
                Expanded(
                    child: _callButton(
                        onPress: () {
                          Navigator.pop(context);
                        },
                        content: '返回',
                        hasLeftBorder: true,
                        isSelect: false)),
                Expanded(
                    child: _callButton(
                        onPress: () {},
                        content: '保存',
                        hasLeftBorder: true,
                        isSelect: true))
              ],
            )
          ],
        ));
  }
}