【问题标题】:How to change text inside bottom sheet dialog in flutter?如何在颤动中更改底部工作表对话框内的文本?
【发布时间】:2021-12-20 19:20:50
【问题描述】:

我想更改底部工作表对话框内文本小部件中的值,但我找不到方法

showBottomDialog(
      context: context,
      allowBackNavigation: true,
      title: "Modifier la photo de profile",
      content: 'Contain TextFormField',
      actions: [
        Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            TextFormField(
              decoration: InputDecoration(
                labelText: 'Nom',
                labelStyle: TextStyle(
                  fontFamily: 'Montserrat',
                  fontWeight: FontWeight.bold,
                  color: Colors.grey,
                ),
                focusedBorder: UnderlineInputBorder(
                  borderSide: BorderSide(
                    color: kPrimaryColor,
                  ),
                ),
              ),
              controller: _nom,
              onChanged: (value){
                setStat(){
                _new_name = value;
                }
                
              },
              validator: (value) {
                if (value == null || value.isEmpty) {
                  return 'Veuillez remplir ce champ';
                }
                return null;
              },
            ),
            SizedBox(height: 10.0),
            Text(_new_name);
])])

我想知道在 TextFormField 中输入内容后,是否有办法在颤振中更改 showModalBottomSheet 中的文本。否则,我需要为 TextFormField 中的每次更改实时更新 Text Widget 中的值。

请帮帮我

【问题讨论】:

    标签: flutter dart bottom-sheet flutter-showmodalbottomsheet


    【解决方案1】:

    showDialog 返回StatefulBuilder

     showBottomDialog(
                context: context,
                builder: (context) => StatefulBuilder(
                  builder: (context, setStateSB) => yourDialogWidget(),
                ),
              );
    
    

    并使用setStateSB 更新对话框内的用户界面,如setStateSB((){....})

    您可以查看this answer,了解有关更新对话框 UI 的更多信息。

    【讨论】:

      猜你喜欢
      • 2020-11-16
      • 2021-12-25
      • 2019-06-15
      • 1970-01-01
      • 2020-04-24
      • 2020-10-08
      • 2021-05-19
      • 2020-05-16
      • 2020-07-21
      相关资源
      最近更新 更多