Image Description

Meterial组件库提供了输入框 Widget TextField。

代码示例

  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(16.0),
      child: Column(
        children: <Widget>[
        TextField(
          //关联focusNode1
          focusNode: focusNode1,
          decoration: InputDecoration(
          labelText: "input1"
          ),
        ),
        TextField(
        //关联focusNode2
        focusNode: focusNode2,
        decoration: InputDecoration(
          labelText: "input2"
          ),
        ),
        Builder(builder: (ctx) {
          return Column(
            children: <Widget>[
            RaisedButton(
            child: Text("移动焦点"),
            onPressed: () {
              if(null == focusScopeNode){
                  focusScopeNode = FocusScope.of(context);
              }
              focusScopeNode.requestFocus(focusNode2);
              }),
              RaisedButton(
                child: Text("隐藏键盘"),
                  onPressed: () {
                    // 当所有编辑框都失去焦点时键盘就会收起  
                    focusNode1.unfocus();
                    focusNode2.unfocus();
                  },
                ),
              ],
            );
          },
        ),
      ],
    ),
  );
}