flutter - how to create forms in popup

后端 未结 3 744
攒了一身酷
攒了一身酷 2020-12-25 13:03

I want to create a form inside a pop-up with flutter like the image below: popup

3条回答
  •  天涯浪人
    2020-12-25 13:59

    Here is an example of code that will allow you to create a button that can produce this kind of popup .

    Code :

    RaisedButton(
              child: Text("Open Popup"),
              onPressed: () {
                showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return AlertDialog(
                        scrollable: true,
                        title: Text('Login'),
                        content: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Form(
                            child: Column(
                              children: [
                                TextFormField(
                                  decoration: InputDecoration(
                                    labelText: 'Name',
                                    icon: Icon(Icons.account_box),
                                  ),
                                ),
                                TextFormField(
                                  decoration: InputDecoration(
                                    labelText: 'Email',
                                    icon: Icon(Icons.email),
                                  ),
                                ),
                                TextFormField(
                                  decoration: InputDecoration(
                                    labelText: 'Message',
                                    icon: Icon(Icons.message ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                         actions: [
                          RaisedButton(
                              child: Text("Submit"),
                              onPressed: () {
                                // your code
                              })
                        ],
                      );
                    });
              },
            ),
    

    Output :

    For more options, you would have to manipulate the properties of the Form widget, the TextField widget or the RaisedButton widget such as autovalidation, decoration, color etc ... If this is not enough , you can use the Dialog widget instead of the AlertDialog widget. But in this case, you will replace the content property with child. And make the necessary modifications.

提交回复
热议问题