【发布时间】:2020-04-13 01:07:02
【问题描述】:
我的应用主页有一个搜索栏。当点击搜索栏时,用户将被重定向到搜索页面,如下所示:
class _HomeAppBarState extends State<HomeAppBar> {
@override
Widget build(BuildContext context) {
return AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.account_circle, color: Colors.black) , onPressed: () => Scaffold.of(context).openDrawer()
),
title: TextField(
onTap: () {Navigator.push(context, MaterialPageRoute(builder: (context) => Search()));},
decoration: InputDecoration(
prefixIcon: Icon(Icons.search, color: Colors.black),
hintText: "Search...",
),
)
);
}
}
在搜索页面中。应用栏有一个后退按钮,然后按下后退按钮我希望用户回到主页。我尝试使用 Navigator.pop 如下:
class _SearchAppBarState extends State<SearchAppBar> {
@override
Widget build(BuildContext context) {
return AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black) , onPressed: () => Navigator.pop(context)
),
title: TextField(
autofocus: true,
//onChanged: Do Stuff here.
decoration: InputDecoration(
prefixIcon: Icon(Icons.search, color: Colors.black),
hintText: "Search App Bar...",
),
)
);
}
}
但是当按下返回按钮时我得到了非常奇怪的结果。
屏幕保持这样,当我再次单击返回按钮时,它停留在搜索页面。
【问题讨论】:
标签: flutter flutter-navigation