diff --git a/lib/ui/routes/main_route/main_route.dart b/lib/ui/routes/main_route/main_route.dart index 49a0b5a..a7df0e9 100644 --- a/lib/ui/routes/main_route/main_route.dart +++ b/lib/ui/routes/main_route/main_route.dart @@ -15,7 +15,7 @@ final mainControllerKey = GlobalKey(); mixin MainRoute implements StatefulWidget {} /// Public interface of home controller -mixin MainController implements State { +abstract class MainController extends State { /// Get current instance of Home controller static MainController of(BuildContext context) { assert(context != null); // A future implementation might need context again @@ -34,7 +34,18 @@ mixin MainController implements State { void openUserFriendsList(int userID); /// Pop current page. Last page can not be popped - void popPage(); + /// + /// If the current route is not the main route, we pop one page + void popPage() { + if(!ModalRoute.of(context).isCurrent) + Navigator.of(context).pop(); + else + doPopPage(); + } + + /// Pop current page. Do not call this method directly. + @protected + void doPopPage(); /// Push a new widget void push(Widget w, {bool hideNavBar}); diff --git a/lib/ui/routes/main_route/smartphone_route.dart b/lib/ui/routes/main_route/smartphone_route.dart index 1daf2fe..4807925 100644 --- a/lib/ui/routes/main_route/smartphone_route.dart +++ b/lib/ui/routes/main_route/smartphone_route.dart @@ -55,7 +55,7 @@ class CurrPage { } /// Private implementation of HomeController -class _MainRouteState extends State implements MainController { +class _MainRouteState extends MainController { CurrPage get _currTab => history.last; List history = List(); @@ -67,7 +67,7 @@ class _MainRouteState extends State implements MainController { } /// Pop the page - void popPage() { + void doPopPage() { if (history.length > 1) history.removeLast(); setState(() {}); } diff --git a/lib/ui/routes/main_route/tablet_route.dart b/lib/ui/routes/main_route/tablet_route.dart index f05c2b7..a2e939b 100644 --- a/lib/ui/routes/main_route/tablet_route.dart +++ b/lib/ui/routes/main_route/tablet_route.dart @@ -17,7 +17,7 @@ class TabletRoute extends StatefulWidget implements MainRoute { _TabletRouteState createState() => _TabletRouteState(); } -class _TabletRouteState extends State implements MainController { +class _TabletRouteState extends MainController { final _conversationsKey = GlobalKey(); @override @@ -88,11 +88,6 @@ class _TabletRouteState extends State implements MainController { // TODO: implement openUserPage } - @override - void popPage() { - // TODO: implement popPage - } - @override void push(Widget w, {bool hideNavBar}) { // TODO: implement push @@ -102,4 +97,9 @@ class _TabletRouteState extends State implements MainController { void startCall(int convID) { // TODO: implement startCall } + + @override + void doPopPage() { + // TODO: implement doPopPage + } }