Skip to content

Commit

Permalink
Go to HomeFragment on back pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
Simone Sestito committed Oct 29, 2018
1 parent e8195b8 commit 2653dbd
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions lib/route/HomeRoute.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,27 @@ class HomeRouteState extends State<HomeRoute> {
children: <Widget>[
Padding(
padding: EdgeInsets.only(bottom: BOTTOM_BAR_HEIGHT),
child: SafeArea(child: currentFragment),
child: SafeArea(
child: WillPopScope(
child: currentFragment,
onWillPop: _willPopCallback,
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: BottomHome(
buttons: <Widget>[
Image.asset("assets/img/ic_home_news.png", color: Colors.white),
GestureDetector(
child: RocketHero(),
onVerticalDragEnd: (_) =>
Navigator.of(context).pushNamed("/faq")),
Image.asset("assets/img/home_collection.png",
color: Colors.white),
child: RocketHero(),
onVerticalDragEnd: (_) =>
Navigator.of(context).pushNamed("/faq"),
),
Image.asset(
"assets/img/home_collection.png",
color: Colors.white,
),
],
clickListener: (index) {
switch (index) {
Expand Down Expand Up @@ -88,4 +96,17 @@ class HomeRouteState extends State<HomeRoute> {
),
);
}

Future<bool> _willPopCallback() async {
if (currentFragment is HomeFragment) {
// Call .pop() as usual
return true;
} else {
// Go back to home fragment
setState(() {
currentFragment = HomeFragment();
});
return false;
}
}
}

0 comments on commit 2653dbd

Please sign in to comment.