1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00

Add [WillPopScope] on tablet mode

This commit is contained in:
Pierre HUBERT 2020-05-11 18:32:58 +02:00
parent f3eda1c89d
commit 620ad0d5cf
3 changed files with 16 additions and 12 deletions

View File

@ -72,6 +72,15 @@ abstract class MainController extends State<MainRoute> {
void popUntilMainRoute() => Navigator.of(context).popUntil((settings) =>
ModalRoute.of(context).isCurrent || !ModalRoute.of(context).isActive);
/// Go to the previous page (use for [WillPop] widget)
@protected
Future<bool> willPop() async {
if (numberOfPages == 1) return true;
popPage();
return false;
}
/// Open notifications page
void openNotificationsPage() => pushPage(PageInfo(
type: PageType.NOTIFICATIONS_PAGE, child: NotificationsScreen()));

View File

@ -21,14 +21,6 @@ class _MainRouteState extends MainController {
PageInfo get defaultPage =>
PageInfo(type: PageType.NOTIFICATIONS_PAGE, child: NotificationsScreen());
/// Allows to go to previous tab
Future<bool> _willPop() async {
if (numberOfPages == 1) return true;
popPage();
return false;
}
@override
Widget build(BuildContext context) {
return Container(
@ -36,7 +28,7 @@ class _MainRouteState extends MainController {
child: SafeArea(
// Avoid OS areas
child: WillPopScope(
onWillPop: _willPop,
onWillPop: willPop,
child: Scaffold(
appBar: currentPage.hideNavBar
? null

View File

@ -32,9 +32,12 @@ class _TabletRouteState extends MainController {
@override
Widget build(BuildContext context) {
return Scaffold(
return WillPopScope(
onWillPop: willPop,
child: Scaffold(
appBar: _buildAppBar(),
body: _buildBody(),
),
);
}