【问题标题】:During switching from TextField to DropDownButton, the last one appears only for a moment and disappears again从TextField切换到DropDownButton时,最后一个只出现片刻,又消失了
【发布时间】:2019-08-23 06:33:07
【问题描述】:

在从文本字段(打开键盘)切换到 dropDownButton 期间,下拉菜单会出现片刻,然后由于键盘关闭而消失

@override
  Widget build(BuildContext context) {
    ...
          child: Form(
            child: Column(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.only(bottom: 8.0),
                  child: Text(
                    "Product name",
                    style: _textStyle,
                  ),
                ),
                TextFormField(
                  autofocus: true,    controller:_newProductPagePresenter.newBakeryNameController,
                  decoration: InputDecoration(
                    fillColor: Colors.white,
                    filled: true,
                    contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
                    border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(8.0)),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(
                      top: 15.0, bottom: 8.0, right: 8.0, left: 8.0),
                  child: Text(
                    "Product category",
                    style: _textStyle,
                  ),
                ),
                DropdownButtonFormField(
                  decoration: InputDecoration(
                      fillColor: Colors.white,
                      filled: true,
                      contentPadding: EdgeInsets.fromLTRB(10.0, 8.0, 10.0, 8.0),
                      border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(8.0))),
                  onChanged: (String value) {
                    setState(() {
                      currentDropDownMenuValue = value;
                    });
                  },
                  value: currentDropDownMenuValue,
//                  items: <String>['Cake', 'Pancake', 'Free', 'Four']
                  items: _productCategories
                      .map<DropdownMenuItem<String>>((ProductCategory category) {
                    return DropdownMenuItem<String>(
                      value: category.id.toString(),
                      child: Text(category.name.en),
                    );
                  }).toList(),
                ),
              ],
            ),
          ),
        ),
...

我需要在它们之间顺利切换,可能要等到键盘关闭才打开dropDownMenu。谢谢!

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    我通过创建自定义 alertDialog 并向其添加 GlobalKey 解决了这个问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多