当我在TextFormField中点击suffixIcon时,防止对TextFormField进行聚焦

时间:2019-10-03 17:14:13

标签: flutter

当我按下按钮时,TextFormField将被聚焦,并且键盘将出现。如何解决此问题?
下面的代码:

data: {download_list: download_list}

2 个答案:

答案 0 :(得分:1)

您可以像这样使用堆栈。

Stack(
  alignment: Alignment.centerRight,
  children: <Widget>[
    TextFormField(
      decoration: InputDecoration(
        labelText: 'verify code',
        prefixIcon: Icon(Icons.sms),
      ),
      keyboardType: TextInputType.number,
    ),
    FlatButton(
      onPressed: () {},
      textTheme: ButtonTextTheme.primary,
      child: Text('send sms'),
    ),
  ],
)

The same question was asked few days ago ...

答案 1 :(得分:1)

点击后缀图标时使用此功能。

() {
  // This will help to wait for TextField to get focus before
  // we unfocus but it will happen fast so that you won't notice.
  Future.delayed(Duration.zero, () {
    _yourInputFocusNode.unfocus();
    // Your implementation to run when tap suffixIcon in TextField
  });
},

示例

TextFormField(
  focusNode: _phoneNumberFocusNode,
  decoration: InputDecoration(
    suffixIcon: IconButton(
      icon: Icon(Icons.contacts),
      onPressed: () {
        Future.delayed(Duration.zero, () {
          _phoneNumberTwoFocusNode.unfocus();
          Navigator.pushNamed(context, 'Contacts');
        });
      },
    ),
  ),
),
相关问题