我想要一个能够让用户输入他们的信息并将其显示在对话框内的 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;});
最佳答案
这是您所要求的一个快速丑示例,只是传递概念:
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/