【发布时间】:2020-10-05 07:12:23
【问题描述】:
这是我的代码:
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()),
),
),
),
在这里,我尝试了一切导航并尝试了 pushNamed 方式和正常推送方式,但没有任何反应,打印工作正常但 Navigator 不起作用,我尝试将 TextField 包装在 Builder 中但仍然无法正常工作,即使它没有显示任何错误,什么也没发生,矛盾的是,当我点击同一个小部件和同一个 AppBar 中的按钮时,它就起作用了。
我需要在键盘上点击回车后进入搜索结果屏幕,我希望有其他方法而不是onSubmitted。
颤振版本 1.22
【问题讨论】:
-
不确定是否相关,但您是否查看了有关 Navigator 2.0 的最新更新?
-
@OsaXma 不,我在哪里可以查看?
-
我搜了一下,写代码有什么区别?
标签: flutter