diff --git a/lib/ui/routes/home_route.dart b/lib/ui/routes/home_route.dart index f0720ba..159bb77 100644 --- a/lib/ui/routes/home_route.dart +++ b/lib/ui/routes/home_route.dart @@ -1,6 +1,5 @@ import 'package:comunic/helpers/account_helper.dart'; import 'package:comunic/ui/routes/app_settings_route.dart'; -import 'package:comunic/ui/routes/user_page_route.dart'; import 'package:comunic/ui/screens/conversations_list_screen.dart'; import 'package:comunic/ui/screens/friends_list_screen.dart'; import 'package:comunic/ui/screens/group_screen.dart'; @@ -8,6 +7,8 @@ import 'package:comunic/ui/screens/groups_list_screen.dart'; import 'package:comunic/ui/screens/newest_posts.dart'; import 'package:comunic/ui/screens/notifications_screen.dart'; import 'package:comunic/ui/screens/other_friends_lists_screen.dart'; +import 'package:comunic/ui/screens/user_access_denied_screen.dart'; +import 'package:comunic/ui/screens/user_page_screen.dart'; import 'package:comunic/ui/widgets/navbar_widget.dart'; import 'package:comunic/utils/account_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; @@ -49,11 +50,16 @@ abstract class HomeController extends State { /// 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 + void popPage(); } /// Private implementation of HomeController @@ -69,8 +75,8 @@ class _HomeRouteState extends HomeController { } /// Pop the page - void _popPage() { - history.removeLast(); + void popPage() { + if (history.length > 1) history.removeLast(); setState(() {}); } @@ -78,7 +84,7 @@ class _HomeRouteState extends HomeController { Future _willPop() async { if (history.length == 1) return true; - _popPage(); + popPage(); return false; } @@ -136,7 +142,10 @@ class _HomeRouteState extends HomeController { return FriendsListScreen(); case BarCallbackActions.OPEN_USER_PAGE: - return UserPageRoute(userID: _currTab.args["userID"]); + return UserPageScreen(userID: _currTab.args["userID"]); + + case BarCallbackActions.OPEN_USER_ACCESS_DENIED_PAGE: + return UserAccessDeniedScreen(userID: _currTab.args["userID"]); case BarCallbackActions.OPEN_GROUPS: return GroupsListScreen(); @@ -212,6 +221,12 @@ class _HomeRouteState extends HomeController { CurrPage(BarCallbackActions.OPEN_USER_PAGE, args: {"userID": userID})); } + @override + void openUserAccessDeniedPage(int userID) { + _pushPage(CurrPage(BarCallbackActions.OPEN_USER_ACCESS_DENIED_PAGE, + args: {"userID": userID})); + } + @override void openUserFriendsList(int userID) { _pushPage(CurrPage(BarCallbackActions.OPEN_USER_FRIENDS_LIST, diff --git a/lib/ui/routes/user_access_denied_route.dart b/lib/ui/screens/user_access_denied_screen.dart similarity index 81% rename from lib/ui/routes/user_access_denied_route.dart rename to lib/ui/screens/user_access_denied_screen.dart index 5b0fd63..8e0f5c0 100644 --- a/lib/ui/routes/user_access_denied_route.dart +++ b/lib/ui/screens/user_access_denied_screen.dart @@ -2,29 +2,29 @@ import 'package:comunic/helpers/friends_helper.dart'; import 'package:comunic/helpers/users_helper.dart'; import 'package:comunic/models/friend_status.dart'; import 'package:comunic/models/user.dart'; -import 'package:comunic/ui/routes/user_page_route.dart'; +import 'package:comunic/ui/routes/home_route.dart'; import 'package:comunic/ui/widgets/FrienshipStatusWidget.dart'; import 'package:comunic/ui/widgets/account_image_widget.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/ui_utils.dart'; import 'package:flutter/material.dart'; -/// User access denied route +/// User access denied screen /// /// @author Pierre HUBERT -class UserAccessDeniedRoute extends StatefulWidget { +class UserAccessDeniedScreen extends StatefulWidget { final int userID; - const UserAccessDeniedRoute({Key key, @required this.userID}) + const UserAccessDeniedScreen({Key key, @required this.userID}) : assert(userID != null), super(key: key); @override - _UserAccessDeniedRouteState createState() => _UserAccessDeniedRouteState(); + _UserAccessDeniedScreenState createState() => _UserAccessDeniedScreenState(); } -class _UserAccessDeniedRouteState extends State { +class _UserAccessDeniedScreenState extends State { final UsersHelper usersHelper = UsersHelper(); final FriendsHelper friendsHelper = FriendsHelper(); @@ -49,14 +49,11 @@ class _UserAccessDeniedRouteState extends State { final user = await usersHelper.getSingleWithThrow(widget.userID); // Check if the two users are friend now - if (status.areFriend) - Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (c) => UserPageRoute( - userID: widget.userID, - ), - ), - ); + if (status.areFriend) { + final controller = HomeController.of(context); + controller.popPage(); + controller.openUserPage(widget.userID); + } setState(() { _status = status; diff --git a/lib/ui/routes/user_page_route.dart b/lib/ui/screens/user_page_screen.dart similarity index 92% rename from lib/ui/routes/user_page_route.dart rename to lib/ui/screens/user_page_screen.dart index 59df0a4..5defd05 100644 --- a/lib/ui/routes/user_page_route.dart +++ b/lib/ui/screens/user_page_screen.dart @@ -3,7 +3,6 @@ import 'package:comunic/helpers/posts_helper.dart'; import 'package:comunic/helpers/users_helper.dart'; import 'package:comunic/models/advanced_user_info.dart'; import 'package:comunic/ui/routes/home_route.dart'; -import 'package:comunic/ui/routes/user_access_denied_route.dart'; import 'package:comunic/ui/widgets/network_image_widget.dart'; import 'package:comunic/ui/widgets/post_create_form_widget.dart'; import 'package:comunic/ui/widgets/posts_list_widget.dart'; @@ -21,18 +20,18 @@ enum _PageStatus { LOADING, ERROR, READY } enum _MenuOptions { FRIENDS_LIST } -class UserPageRoute extends StatefulWidget { +class UserPageScreen extends StatefulWidget { final int userID; - const UserPageRoute({Key key, @required this.userID}) + const UserPageScreen({Key key, @required this.userID}) : assert(userID != null), super(key: key); @override - _UserPageRouteState createState() => _UserPageRouteState(); + _UserPageScreenState createState() => _UserPageScreenState(); } -class _UserPageRouteState extends State { +class _UserPageScreenState extends State { // Helpers final usersHelper = UsersHelper(); final PostsHelper _postsHelper = PostsHelper(); @@ -77,14 +76,11 @@ class _UserPageRouteState extends State { } on GetUserAdvancedUserError catch (e) { _setStatus(_PageStatus.ERROR); - if (e.cause == GetUserAdvancedInformationErrorCause.NOT_AUTHORIZED) - Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (c) => UserAccessDeniedRoute( - userID: widget.userID, - ), - ), - ); + if (e.cause == GetUserAdvancedInformationErrorCause.NOT_AUTHORIZED) { + final controller = HomeController.of(context); + controller.popPage(); + controller.openUserAccessDeniedPage(widget.userID); + } } } diff --git a/lib/ui/widgets/navbar_widget.dart b/lib/ui/widgets/navbar_widget.dart index a2e1eff..8f3a00d 100644 --- a/lib/ui/widgets/navbar_widget.dart +++ b/lib/ui/widgets/navbar_widget.dart @@ -18,6 +18,7 @@ enum BarCallbackActions { OPEN_GROUPS, OPEN_GROUP_PAGE, OPEN_USER_PAGE, + OPEN_USER_ACCESS_DENIED_PAGE, OPEN_APP_SETTINGS, OPEN_USER_FRIENDS_LIST, OPEN_ABOUT_DIALOG,