dart - 如何创建一个能够接受文本输入并显示 flutter 结果的对话框?

标签 dart flutter

我想要一个能够让用户输入他们的信息并将其显示在对话框内的 ListView 中的对话框。

这是我用于 ListView 的代码。

new ListView.builder(
            itemBuilder: (context, index) {
              return _infos.isNotEmpty
                  ? new ListTile(
                      title: new Text(_infos[index].toMap().toString()),
                    )
                  : null;
            },
            shrinkWrap: true,
          )

这是我在文本字段的 onchange 中使用的代码

setState(() {_infos= _result;});

最佳答案

这是您所要求的一个快速示例,只是传递概念:

enter image description here

class DialogExample extends StatefulWidget {

  @override
  _DialogExampleState createState() => new _DialogExampleState();
}

class _DialogExampleState extends State<DialogExample> {
  String _text = "initial";
  TextEditingController _c;
  @override
  initState(){
    _c = new TextEditingController();
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Text(_text),
            new RaisedButton(onPressed: () {
              showDialog(child: new Dialog(
                child: new Column(
                  children: <Widget>[
                    new TextField(
                        decoration: new InputDecoration(hintText: "Update Info"),
                        controller: _c,

                    ),
                    new FlatButton(
                      child: new Text("Save"),
                      onPressed: (){
                        setState((){
                        this._text = _c.text;
                      });
                      Navigator.pop(context);
                      },
                    )
                  ],
                ),

              ), context: context);
            },child: new Text("Show Dialog"),)
          ],
        )
      ),
    );
  }
}

关于dart - 如何创建一个能够接受文本输入并显示 flutter 结果的对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49778217/

相关文章:

regex - Dart:使用正则表达式删除字符串中的空格

flutter - 无法创建 Aqueduct 项目

dart - 文本不会在行中溢出

flutter - 任务 ':path_provider:extractDebugAnnotations' 执行失败

flutter - 如何使用 StreamBuilder 更新 TextField 的值?

android - 如何在 flutter sdk 1.2.1 上获取当前位置

firebase - flutter/Dart 错误 : The argument type 'Future<File>' can't be assigned to the parameter type 'File'

arrays - Dart:如何将简单的 map 转换为 dart/flutter 中的列表?

android - 如何让 Flutter 模块在原生 Android Activity 启动二级路由后返回原生 Android Activity?

Flutter网站网址导航