一点点的价值给我无效
当我单击“升高”按钮时,我正在打印无效。
如果用户不输入任何内容,我想查看初始值。 如果对初始值进行修改,则打印语句应打印修改后的语句(其中)。
代码:
class _HomeState extends State<Home> {
var _input;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('hello')),
body: Column(
children: [
TextFormField(
initialValue: 'initial value ',
onChanged: (text) {
setState(() {
_input = text;
});
},
),
RaisedButton(
onPressed: () {
print(_input);
},
child: Text('Press me'),
)
],
),
);
}
}
如果我不编辑TextFormField输出,
flutter: null
则输出如果我编辑TextFormField
flutter: initial value test
I am printing null when I am clicking the raised button.
I want to see the initialValue if the user doesnot enter any thing.
If the modifies the initialValue then the print statement should print the modified statement(which it does).
Code:
class _HomeState extends State<Home> {
var _input;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('hello')),
body: Column(
children: [
TextFormField(
initialValue: 'initial value ',
onChanged: (text) {
setState(() {
_input = text;
});
},
),
RaisedButton(
onPressed: () {
print(_input);
},
child: Text('Press me'),
)
],
),
);
}
}
Output if I dont edit the TextFormField
flutter: null
Output if I edit the TextFormField
flutter: initial value test
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用
textedingcontroller
,那会更好。有关
textededingingcontroller
。如果您仍然使用该变量,请在变量上初始化文本并使用它。
另外,您可以使其无效,并检查它是否为null,然后提供默认值,在这种情况下似乎不需要。
It would be better if you use
TextEditingController
.More about
TextEditingController
.If you still use the variable, initialize the text on variable and use it.
Also you can make it nullable and check if it is null then provide default value which is seeming unnecessary in this case.