Discuz!NT|BBS|论坛

注册

 

发新话题 回复该主题

flutter中为TextField设置初始值的代码如下: [复制链接]

1#
class _FooState extends State<Foo> {
  TextEditingController _controller;

  @override
  void initState() {
    super.initState();
    _controller = new TextEditingController(text: '初始值');
  }

  @override
  Widget build(BuildContext context) {
    return new Column(
      children: <Widget>[
        new TextField(
          //设置controller,
          controller: _controller,
        ),
        new RaisedButton(
          onPressed: () {
            //清除输入
            _controller.clear();
          },
          child: new Text('清除'),
        ),
      ],
    );
  }
}
分享 转发
TOP
发新话题 回复该主题