【发布时间】:2019-10-18 19:42:57
【问题描述】:
我有输入文本字段:Foo /line1 条形/line2
当我单击按钮提交时,我使用提交的值(名称=foo 和名称=bar)创建小部件“名称:”,我如何从该文本字段创建和获取值?我必须先制作一个列表视图构建器吗?
谁能举个例子,
String txt = "";
TextEditingController controllerTxt = new TextEditingController();
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: Text('Create'),
actions: <Widget>[
FlatButton(
child: Text('Submit'),
textColor: Colors.white,
onPressed: () {
Navigator.pushNamed(context, '/ResultPage',
arguments: (controllerTxt.text));
},
),
],
),
body: new ListView(
children: <Widget>[
new Container(
child: new Column(
children: <Widget>[
new TextField(
controller: controllerTxt,
maxLines: 25,
),
],
),
),
],
),
);
}
class _ResultPageState extends State<ResultPage> {
String result;
@override
Widget build(BuildContext context) {
RouteSettings settings = ModalRoute.of(context).settings;
result = settings.arguments;
return new Scaffold(
appBar: new AppBar(
title: Text('Create'),
actions: <Widget>[
],
),
body: new Container(
padding: EdgeInsets.all(10.0),
child: new Row(
children: <Widget>[
new Text('Name : '),
Expanded(
child: new TextField(
enabled: false,
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderSide: new BorderSide(color: Colors.black)),
labelText: ('${result}'),
),
)),
],
),
),
);
}
}
【问题讨论】:
-
你为什么不使用两个文本字段?
-
@PraneethDhanushkaFernando,我尝试从每一行制作循环小部件
-
你能再解释一下吗。所以想象提交的文本是,Foo /line1 Bar /line2 你想从这两行中做什么