简体   繁体   English

为什么导航器在颤动中不能在 TextField 的 onSubmitted 中工作?

[英]Why navigator not working in onSubmitted of TextField in flutter?

This is my code:这是我的代码:

AppBar(
        actions: [
          IconButton(
            icon: Icon(Icons.search),
            onPressed: () => Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => SearchScreen(
                  query: _query,
                ),
              ),
            ),
          ),
        ],
        title: Container(
          height: 40,
          decoration: BoxDecoration(
            color: kSecondaryColor.withOpacity(0.1),
            borderRadius: BorderRadius.circular(15),
          ),
          child: TextField(
            onSubmitted: (value) {
              print('HHi');
              _query.searchBy = value;
              Navigator.popAndPushNamed(context, '/ads');
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => SearchScreen(
                    query: _query,
                  ),
                ),
              );
            },
            decoration: InputDecoration(
                border: InputBorder.none,
                enabledBorder: InputBorder.none,
                focusedBorder: InputBorder.none,
                prefixIcon: Icon(Icons.search),
                isDense: true,
                contentPadding:
                    EdgeInsets.symmetric(vertical: lang == 'en' ? 11 : 5),
                hintText: 'Search'.tr()),
          ),
        ),
      ),

Here I tried everything to navigate and tried the pushNamed way and normal push way but nothing happened, the print is works but Navigator is not works, and I tried wrap TextField in Builder and still not working, even it's not shows any errors, nothing happening, The paradox is it's works when I click on button in the same widget and the same AppBar.在这里,我尝试了所有导航并尝试了 pushNamed 方式和正常推送方式,但没有发生任何事情,打印有效但 Navigator 无效,我尝试将 TextField 包装在 Builder 中但仍然无法正常工作,即使它没有显示任何错误,也没有发生任何事情,矛盾的是,当我单击同一个小部件和同一个 AppBar 中的按钮时,它是有效的。

I need push into search result screen after click on enter on keyboard, I hope if there another way instead of onSubmitted.单击键盘上的 Enter 后,我需要推送到搜索结果屏幕,我希望是否有其他方法而不是 onSubmitted。

flutter version 1.22颤振版本 1.22

Need to pressed enter key of your keyboard.需要按下键盘的回车键。 and focus out from you text field.并专注于您的文本字段。

Check Here检查这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM