TextField inside CupertinoAlertDialog

Issue

I’m making a dialog, which has a text field to get input from user, by using CupertinoAlertDialog. However, it keeps saying No Mater Widget Found. I searched and tried with some solution from the Internet but it didn’t work.
Here is my code

showCupertinoDialog(
   context: context,
   builder: (context) {
    return CupertinoAlertDialog(
     content: Scaffold(
     body: TextField(
     controller: cubit.textEditingController,
     ),
    ),
   );
 }
);

I have tried to replace Material with Card, Scaffold and Container but it didn’t work as well.

Please help me

Solution

Please Wrap your cupertinoAlertDialog inside ShowDialog as it has Material Widget property.

showDialog<bool>(
              context: context,
              builder: (context) {
                return CupertinoAlertDialog(
                  title: Text('Cupertino dialog'),
                  content: Card(
                    elevation: 10.0,
                    child: Column(
                      children: <Widget>[
                        TextField(
                          decoration: InputDecoration(
                              labelText: "Name",
                              filled: true,
                              fillColor: Colors.grey
                          ),
                        ),
                      ],
                    ),
                  ),
                );
              },
            );

Answered By – Jahidul Islam

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *