Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 无数据弹出/推送到当前屏幕_Flutter_Dart_Flutter Layout - Fatal编程技术网

Flutter 无数据弹出/推送到当前屏幕

Flutter 无数据弹出/推送到当前屏幕,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我试图在没有返回数据的情况下弹出。 我有一个屏幕,其中有4个底部导航器,每个按钮有4个布局 LayoutType.table: (_) => Page1( layoutGroup: _layoutGroup, onLayoutToggle: _onLayoutGroupToggle), LayoutType.favorite: (_) => Page2( layoutGroup: _layoutGroup, onLayo

我试图在没有返回数据的情况下弹出。 我有一个屏幕,其中有4个底部导航器,每个按钮有4个布局

      LayoutType.table: (_) => Page1(
          layoutGroup: _layoutGroup, onLayoutToggle: _onLayoutGroupToggle),
      LayoutType.favorite: (_) => Page2(
          layoutGroup: _layoutGroup, onLayoutToggle: _onLayoutGroupToggle),
      LayoutType.menu: (_) => Page3(
          layoutGroup: _layoutGroup, onLayoutToggle: _onLayoutGroupToggle),
      LayoutType.custom: (_) => Page4(
          layoutGroup: _layoutGroup, onLayoutToggle: _onLayoutGroupToggle),
    }[_layoutSelection](context);
在第3页,我有一个带有文本字段和flatbutton的showdialog内容add,在我按下add后,我需要回到第3页,我尝试使用pop,但如果我再次按下add按钮,它将返回我添加的最后一个数据

有没有办法弹出返回数据? 我尝试使用Push/PushNamed,但它总是返回到第一个屏幕第1页

class MenuPage extends StatefulWidget implements HasLayoutGroup {
  MenuPage({Key key, this.layoutGroup, this.onLayoutToggle}) : super(key: key);
  final LayoutGroup layoutGroup;
  final VoidCallback onLayoutToggle;

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

class _MenuPageState extends State<MenuPage> {
  double _width;
  double _height;
  String menuName;
  String menuPrice;
  String menuCategory;
  String selectedCategory;
  final formatPrice = NumberFormat.simpleCurrency();
  var menu;
  crudMedthods crudObj = new crudMedthods();
  List _categorymenu = ["Food", "Beverage", "Liquor", "Electricity", "Others"];
  final _textEditingMenu = TextEditingController();
  final _textEditingPrice = TextEditingController();
  List<DropdownMenuItem<String>> _dropDownMenuItems;
  String _currentCategory;

  List<DropdownMenuItem<String>> getDropDownMenuItems() {
    List<DropdownMenuItem<String>> items = List();
    for (String catmenu in _categorymenu) {
      items.add(DropdownMenuItem(value: catmenu, child: Text(catmenu)));
    }
    return items;
  }

  @override
  void dispose() {

    _textEditingMenu.dispose();
    _textEditingPrice.dispose();
    super.dispose();
  }

  @override
  void initState() {
    _dropDownMenuItems = getDropDownMenuItems();
    _currentCategory = _dropDownMenuItems[0].value;
    crudObj.getDataMenu().then((results) {
      setState(() {
        menu = results;
      });
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    _width = MediaQuery.of(context).size.width;
    _height = MediaQuery.of(context).size.height;
    return Container(
      child: Column(
        children: <Widget>[
          Container(
            width: _width,
            height: 70,
            child: Card(
              elevation: 2,
              color: Colors.amber[300],
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(10))),
              child: Row(
                children: <Widget>[
                  Container(
                    alignment: Alignment.topLeft,
                    margin: EdgeInsets.all(10),
                    child: IconButton(
                      icon: Icon(FontAwesomeIcons.search),
                      onPressed: () {},
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.all(295),
                  ),
                  Container(
                    alignment: Alignment.topRight,
                    margin: EdgeInsets.all(10),
                    child: IconButton(
                      icon: Icon(FontAwesomeIcons.plus),
                      onPressed: () {
                        addMenu(context);
                      },
                    ),
                  ),
                ],
              ),
            ),
          ),
          Container(
            width: _width,
            height: 584,
            child: Card(
              elevation: 2,
              color: Colors.lightBlueAccent[100],
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(10))),
              child: Container(child: _menuList()),
            ),
          ),
        ],
      ),
    );
  }

  // void changedDropDownItem(String selectedCategory) {
  //   setState(() {
  //     _currentCategory = selectedCategory;
  //   });
  // }

  Future<bool> addMenu(BuildContext context) async {
    return showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text('Add Menu', style: TextStyle(fontSize: 15.0)),
            content: Container(
              height: 300,
              width: 300,
              child: Column(
                children: <Widget>[
                  TextField(
                    controller: _textEditingMenu,
                    textInputAction: TextInputAction.next,
                    decoration: InputDecoration(hintText: 'Enter Menu Name'),
                    onChanged: (value) {
                      this.menuName = value;
                    },
                  ),
                  SizedBox(height: 5.0),
                  TextField(
                    controller: _textEditingPrice,
                    keyboardType: TextInputType.number,
                    decoration: InputDecoration(hintText: 'Enter Price'),
                    onChanged: (value) {
                      this.menuPrice = value;
                    },
                  ),
                  SizedBox(height: 5.0),
                  DropdownButton(
                    isExpanded: true,
                    value: _currentCategory,
                    items: _dropDownMenuItems,
                    onChanged: (String value) {
                      setState(() {
                        _currentCategory = selectedCategory;
                      });
                      menuCategory = value;
                    },
                  ),
                  SizedBox(height: 5.0),
                  Row(
                    children: <Widget>[
                      FlatButton(
                        child: Text('Add'),
                        textColor: Colors.blue,
                        onPressed: () {
                          if (!UtilsImporter()
                              .commanUtils
                              .validateMenuName(menuName)) {
                            UtilsImporter().commanUtils.showToast(
                                UtilsImporter().stringUtils.retrunMenuName,
                                context);
                          } else if (!UtilsImporter()
                              .commanUtils
                              .validateGuestPax(menuPrice)) {
                            UtilsImporter().commanUtils.showToast(
                                UtilsImporter().stringUtils.returnMenuPrice,
                                context);
                          } else if (!UtilsImporter()
                              .commanUtils
                              .validateMenuCategory(menuCategory)) {
                            UtilsImporter().commanUtils.showToast(
                                UtilsImporter().stringUtils.returnMenuCat,
                                context);
                          } else {
                            crudObj.addMenu({
                              'menuName': this.menuName,
                              'menuPrice': this.menuPrice,
                              'menuCategory': this.menuCategory,
                            }).then((result) {
                              // dialogTrigger(context);
                            }).catchError((e) {
                              print(e);
                            });
                            Navigator.of(context).pop();
                            // Navigator.of(context).pop();
                            // Navigator.of(context)
                            //     .pushReplacementNamed('/Dashboard');
                          }
                        },
                      ),
                      Padding(
                        padding: EdgeInsets.all(60),
                      ),
                      FlatButton(
                        child: Text('Return'),
                        textColor: Colors.blue,
                        onPressed: () {
                          Navigator.of(context).pop();
                        },
                      )
                    ],
                  ),
                ],
              ),
            ),
          );
        });
  }
}

class MenuPage扩展StatefulWidget实现HasLayoutGroup{
菜单页({Key-Key,this.layoutGroup,this.onLayoutToggle}):超级(Key:Key);
最终布局组布局组;
最终VoidCallback onLayoutToggle;
@凌驾
_MenuPageState createState()=>MenuPageState();
}
类_MenuPageState扩展状态{
双倍宽度;
双倍高度;
字符串菜单名;
弦菜单;
弦函数范畴;
字符串选择类别;
最终格式价格=NumberFormat.simpleCurrency();
var菜单;
crudMedthods crudObj=新的crudMedthods();
清单_categorymenu=[“食品”、“饮料”、“酒类”、“电力”、“其他”];
最终_textededitingmenu=textededitingcontroller();
最终_textEditingPrice=TextEditingController();
列表-下拉菜单项;
字符串currentCategory;
列表getDropDownMenuItems(){
列表项=列表();
用于(类别菜单中的字符串catmenu){
添加(DropdownMenuItem(值:catmenu,子项:Text(catmenu)));
}
退货项目;
}
@凌驾
无效处置(){
_textEditingMenu.dispose();
_textEditingPrice.dispose();
super.dispose();
}
@凌驾
void initState(){
_dropDownMenuItems=getDropDownMenuItems();
_currentCategory=\u dropDownMenuItems[0]。值;
crudObj.getDataMenu().then((结果){
设置状态(){
菜单=结果;
});
});
super.initState();
}
@凌驾
小部件构建(构建上下文){
_宽度=MediaQuery.of(context).size.width;
_height=MediaQuery.of(context).size.height;
返回容器(
子:列(
儿童:[
容器(
宽度:_宽度,
身高:70,
孩子:卡片(
标高:2,
颜色:颜色。琥珀色[300],
形状:圆形矩形边框(
borderRadius:borderRadius.all(半径.圆形(10)),
孩子:排(
儿童:[
容器(
对齐:alignment.topLeft,
保证金:所有(10),
孩子:我的钮扣(
图标:图标(FontAwesomeIcons.search),
按下:(){},
),
),
填充物(
填充:边缘设置。全部(295),
),
容器(
对齐:alignment.topRight,
保证金:所有(10),
孩子:我的钮扣(
图标:图标(FontAwesomeIcons.plus),
已按下:(){
添加菜单(上下文);
},
),
),
],
),
),
),
容器(
宽度:_宽度,
身高:584,
孩子:卡片(
标高:2,
颜色:Colors.lightBlueAccent[100],
形状:圆形矩形边框(
borderRadius:borderRadius.all(半径.圆形(10)),
子:容器(子:_menuList()),
),
),
],
),
);
}
//void changedDropDownItem(字符串选择类别){
//设置状态(){
//\u currentCategory=所选类别;
//   });
// }
未来添加菜单(构建上下文上下文)异步{
返回显示对话框(
上下文:上下文,
禁止:错误,
生成器:(BuildContext上下文){
返回警报对话框(
标题:文本(“添加菜单”,样式:TextStyle(fontSize:15.0)),
内容:容器(
身高:300,
宽度:300,
子:列(
儿童:[
文本字段(
控制器:_text编辑菜单,
textInputAction:textInputAction.next,
装饰:输入装饰(hintText:“输入菜单名”),
一旦更改:(值){
this.menuName=值;
},
),
尺寸箱(高度:5.0),
文本字段(
控制器:_textededitingprice,
键盘类型:TextInputType.number,
装饰:输入装饰(hintText:“输入价格”),
一旦更改:(值){
this.menuPrice=值;
},
),
尺寸箱(高度:5.0),
下拉按钮(
是的,
值:_currentCategory,
项目:_下拉菜单项,
onChanged:(字符串值){
设置状态(){
_currentCategory=selectedCategory;
});
menuCategory=值;
},
),
尺寸箱(高度:5.0),
划船(
儿童:[
扁平按钮(
子项:文本('Add'),
textColor:Colors.blue,
已按下:(){
如果(!UtilsImporter()
.commanUtils
.validateUname(menuName)){
UtilsImporter().comm
    final myController1 = TextEditingController();
    final myController2 = TextEditingController();

     @override
      void dispose() {
        // Clean up the controller when the widget is removed from the
        // widget tree.
        myController1.dispose();
        myController2.dispose();
        super.dispose();
      }