Home > Mobile >  How to change text inside bottom sheet dialog in flutter?
How to change text inside bottom sheet dialog in flutter?

Time:11-08

I want to change the value in text widget inside the bottom sheet dialog but I can't find a way to do it

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);
])])

I want to know if there is a way to change a text inside showModalBottomSheet in flutter after typing something in TextFormField. Otherwise, I need to update the value in the Text Widget for every change in the TextFormField in realtime.

HELP me please

CodePudding user response:

on showDialog return StatefulBuilder.

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

And use setStateSB to update UI inside dialog like setStateSB((){....})

You can check this answer for more about updating UI on dialog.

  • Related