Flutter:焦点下一个TextFormField在模态中不起作用

时间:2020-10-01 22:50:21

标签: flutter keyboard focus next

当用户按下键盘上的下一个按钮时,我想关注下一个TextFormField。 但是,当我按下下一步按钮时,键盘就消失了。没有焦点。 是不是因为ShowModalBottomSheet-Function而存在问题?

我该如何解决?

showModalBottomSheet(
        context: context,
        builder: (builder) {
          return addSheet(this);
        });
Container addSheet(State state){

  return new Container(
    height: 400.0,
    color: Color(0xFF737373),
    child: new Container(
        decoration: new BoxDecoration(
            color: Colors.white,
            borderRadius: new BorderRadius.only(
                topLeft: const Radius.circular(8.0), topRight: const Radius.circular(8.0))),
        child: Padding(
            padding: EdgeInsets.all(15.0),
            child: new Column(
              children: [
                TextFormField(
                  decoration: InputDecoration(
                      labelText: 'Mushroom Type',
                      hintText: 'Golden Oysters'
                  ),
                  autofocus: true,
                  focusNode: _mushroomTypeFocus,
                  textInputAction: TextInputAction.next,
                  onFieldSubmitted: (String value) {
                    FocusScope.of(state.context).requestFocus(_cultureTypeFocus);
                  },
                ),
                TextFormField(
                  decoration: InputDecoration(
                      labelText: 'Culture Type',
                      hintText: 'liquid culture, bag culture'
                  ),
                  focusNode: _cultureTypeFocus,
                )
              ]
            ),

        )
    )
  );
}

final FocusNode _mushroomTypeFocus = new FocusNode();
final FocusNode _cultureTypeFocus = new FocusNode();

enter image description here

0 个答案:

没有答案