【发布时间】:2019-05-12 09:26:47
【问题描述】:
我的 Flutter Project 结构是这样的
Main() //Run App with MaterialApp and Routes
L HomePage() //Default route (/), with BottomNavigation
L MoviesPage() //Default BottomNavigation Index and shows a list of movies form TMDB
L DetailsPage()
L SeriesPage()
L SupportPage()
点击任何电影后,它会向前导航到 DetailsPage(),但是当我从 DetailsPage() 调用 Navigator.pop 时,它应该返回上一个屏幕,但它没有。
Navigator.canPop(context) return false 但是硬件后退按钮工作得很好,那我该如何解决呢?
main.dart
class BerryMain extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home: Inferno(
{
'/': (context, argumets) => HomePage(),
'/detailspage': (context, arguments) => DetailsPage(arguments),
},
).home(context),
);
}
}
主页
class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _HomePageState();
}
}
class _HomePageState extends State<HomePage> {
int _currentIndex = 0;
final List<Widget> _childnav = [MoviesPage(), SeriesPage(), SupportPage()];
void onTabPressed(...)
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text('...'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
)
],
),
body: _childnav[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
onTap: onTabPressed,
currentIndex: _currentIndex, //this property defines current active tab
items: [
BottomNavigationBarItem(
icon: Icon(Icons.movie), title: Text('Movies')),
BottomNavigationBarItem(icon: Icon(Icons.tv), title: Text('Series')),
BottomNavigationBarItem(icon: Icon(Icons.help), title: Text('Help'))
],
),
);
}
}
电影页面
//Inside ListView Builder
Virgil.pushNamed(context, '/detailspage', arguments: args);
详情页面
//Inside MaterialApp > Scaffold > SliverAppbar > BackButton
Navigator.pop(context)
我正在使用Virgil,但我认为这不是问题。
【问题讨论】:
-
Navigator#canPop()返回什么? -
@pskink 它返回 false
-
尝试重现但无法基于您提供的 sn-ps。也许
MoviesPage中有一些关于上下文的问题。 -
@JRomero 看看这个 repo:gist.github.com/purplecandy/076071650dc233ffcadc934c13a0bf44