解除Flutter

时间:2019-05-20 10:45:17

标签: dart flutter

当我关闭它时,我在AlertDialog中使用一个表单,我想清除TextFormField值。 注意:我想在不使用按钮取消的情况下退出,

   AlertDialog( shape: RoundedRectangleBorder(
     borderRadius: BorderRadius.all(
      Radius.circular(32.0))),
 contentPadding: EdgeInsets.only(top: 10.0),
    content: Container(
        width: 300.0,
          child: Column(
                mainAxisAlignment:
                 MainAxisAlignment.start,
             crossAxisAlignment:
             CrossAxisAlignment.stretch,
             mainAxisSize: MainAxisSize.min,
             children: <Widget>[
                Padding(
               padding: EdgeInsets.only(
               left: 30.0, right: 30.0),
                 child: Column(
                children: <Widget>[
                  TextFormField(
                    controller:
                    _supportController,
             decoration:
        new InputDecoration(
               contentPadding:
       const EdgeInsets
                             .symmetric(
                      vertical: 5.0,
                horizontal:15.0),
        suffixIcon: IconButton(
       icon: Icon(     Icons.search),
        onPressed: null),
           fillColor: Colors.white
               .withOpacity(.8),
          filled: true,
          labelText: 'Support',     ),     ),

2 个答案:

答案 0 :(得分:0)

使用TextEditingController,您可以执行以下操作:

_supportController.clear();

答案 1 :(得分:0)

void _showDialog() async {
    await showDialog(
      context: context,
      builder: (BuildContext context) {
        // return object of type Dialog
        return AlertDialog(
          title: new Text("Alert Dialog title"),
          content: Container(
              width: 300,
              height: 200.0,
              child: Column(
                children: <Widget>[
                  TextFormField(
                    controller: _supportController,
                    decoration: new InputDecoration(
                      contentPadding: const EdgeInsets.symmetric(
                          vertical: 5.0, horizontal: 15.0),
                      suffixIcon:
                          IconButton(icon: Icon(Icons.search), onPressed: null),
                      fillColor: Colors.white.withOpacity(.8),
                      filled: true,
                      labelText: 'Support',
                    ),
                  )
                ],
              )),
          actions: <Widget>[
            new FlatButton(
              child: new Text("Close"),
              onPressed: () {
                _supportController.clear();
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    ).then((val) {
      _supportController.clear();
    });
  }