From 73a94f5358b8656e6251b5486a0d9d276d7a43fa Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 1 Jul 2019 12:06:14 +0200 Subject: [PATCH] Added the "My Page" button to the new app bar --- lib/ui/routes/home_route.dart | 16 +++++++++++++++- lib/ui/widgets/navbar_widget.dart | 31 +++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/lib/ui/routes/home_route.dart b/lib/ui/routes/home_route.dart index f39a86a..96c6dac 100644 --- a/lib/ui/routes/home_route.dart +++ b/lib/ui/routes/home_route.dart @@ -3,7 +3,9 @@ import 'package:comunic/ui/screens/conversations_list_screen.dart'; import 'package:comunic/ui/screens/friends_list_screen.dart'; import 'package:comunic/ui/screens/newest_posts.dart'; import 'package:comunic/ui/widgets/navbar_widget.dart'; +import 'package:comunic/utils/account_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; +import 'package:comunic/utils/navigation_utils.dart'; import 'package:comunic/utils/ui_utils.dart'; import 'package:flutter/material.dart'; @@ -42,6 +44,13 @@ class _HomeRouteState extends State { void _onTap(BarCallbackActions action) { /// Check more quick actions switch (action) { + + /// Open current user page + case BarCallbackActions.OPEN_MY_PAGE: + _openCurrentUserPage(); + break; + + /// Logout user case BarCallbackActions.ACTION_LOGOUT: _logoutRequested(); break; @@ -97,6 +106,11 @@ class _HomeRouteState extends State { ); } + /// Open current user page + Future _openCurrentUserPage() async { + openUserPage(context: context, userID: userID()); + } + /// Handle logout requests from user Future _logoutRequested() async { if (!await showConfirmDialog( @@ -106,7 +120,7 @@ class _HomeRouteState extends State { await AccountHelper().signOut(); - Navigator.pushReplacement(context, MaterialPageRoute(builder: (c){ + Navigator.pushReplacement(context, MaterialPageRoute(builder: (c) { return LoginRoute(); })); } diff --git a/lib/ui/widgets/navbar_widget.dart b/lib/ui/widgets/navbar_widget.dart index 140df5f..5d6e49f 100644 --- a/lib/ui/widgets/navbar_widget.dart +++ b/lib/ui/widgets/navbar_widget.dart @@ -12,6 +12,7 @@ enum BarCallbackActions { OPEN_CONVERSATIONS, OPEN_NEWEST_POSTS, OPEN_FRIENDS, + OPEN_MY_PAGE, NONE, ACTION_LOGOUT } @@ -37,6 +38,16 @@ class _MenuItem { assert(isMenu != null); } +/// Item of action menu +class _ActionMenuItem { + final String label; + final BarCallbackActions action; + + const _ActionMenuItem({@required this.label, @required this.action}) + : assert(label != null), + assert(action != null); +} + /// List of menu items to show final _menuItems = <_MenuItem>[ _MenuItem( @@ -58,6 +69,14 @@ final _menuItems = <_MenuItem>[ action: BarCallbackActions.NONE) ]; +/// List of menu actions items +final _menuActionsItem = <_ActionMenuItem>[ + _ActionMenuItem( + label: tr("My Page"), action: BarCallbackActions.OPEN_MY_PAGE), + _ActionMenuItem( + label: tr("Sign out"), action: BarCallbackActions.ACTION_LOGOUT), +]; + /// Public widget class ComunicAppBar extends StatelessWidget implements PreferredSizeWidget { final OnSelectMenuAction onTap; @@ -140,12 +159,12 @@ class _MenuItemWidget extends StatelessWidget { Widget _buildContextMenuPopupButton() { return PopupMenuButton( child: _buildIconContainer(), - itemBuilder: (i) => [ - PopupMenuItem( - child: Text(tr("Logout")), - value: BarCallbackActions.ACTION_LOGOUT, - ) - ], + itemBuilder: (i) => _menuActionsItem + .map((f) => PopupMenuItem( + child: Text(f.label), + value: f.action, + )) + .toList(), onSelected: onTap, ); }