import 'package:flutter/material.dart'; /// Abstract main application route /// /// This mixin contains methods available in all display modes /// /// @author Pierre Hubert /// Main controller key statically shared across application /// /// Do not use it directly to avoid context leak, instead use the access method /// [MainController.of] final mainControllerKey = GlobalKey(); mixin MainRoute implements StatefulWidget {} /// Public interface of home controller 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 return mainControllerKey.currentState; } /// Pop until main route is reached void popUntilMainRoute() => Navigator.of(context).popUntil((settings) => ModalRoute.of(context).isCurrent || !ModalRoute.of(context).isActive); /// Open user page void openUserPage(int userID); void openUserAccessDeniedPage(int userID); /// Open a specific group page specified by its [groupID] void openGroup(int groupID); /// Display the list of friends of a user void openUserFriendsList(int userID); /// Pop current page. Last page can not be popped /// /// 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, bool allowAsDialog}); /// Open a conversation void openConversation(int convID, {fullScreen: false}); /// Start a call for a given conversation void startCall(int convID); }