diff --git a/lib/ui/routes/home_route.dart b/lib/ui/routes/home_route.dart index b369ee5..f39a86a 100644 --- a/lib/ui/routes/home_route.dart +++ b/lib/ui/routes/home_route.dart @@ -1,12 +1,14 @@ +import 'package:comunic/helpers/account_helper.dart'; import 'package:comunic/ui/screens/conversations_list_screen.dart'; import 'package:comunic/ui/screens/friends_list_screen.dart'; -import 'package:comunic/ui/screens/menus_screen.dart'; import 'package:comunic/ui/screens/newest_posts.dart'; -import 'package:comunic/ui/tiles/custom_bottom_navigation_bar_item.dart'; import 'package:comunic/ui/widgets/navbar_widget.dart'; import 'package:comunic/utils/intl_utils.dart'; +import 'package:comunic/utils/ui_utils.dart'; import 'package:flutter/material.dart'; +import 'login_route.dart'; + /// Main route of the application /// /// @author Pierre HUBERT @@ -38,8 +40,16 @@ class _HomeRouteState extends State { /// Handles a new tab being tapped void _onTap(BarCallbackActions action) { - if (_currTab != action) history.add(action); - _changeTab(action); + /// Check more quick actions + switch (action) { + case BarCallbackActions.ACTION_LOGOUT: + _logoutRequested(); + break; + + default: + if (_currTab != action) history.add(action); + _changeTab(action); + } } @override @@ -86,4 +96,18 @@ class _HomeRouteState extends State { ), ); } + + /// Handle logout requests from user + Future _logoutRequested() async { + if (!await showConfirmDialog( + context: context, + message: tr("Do you really want to sign out from the application ?"), + title: tr("Sign out"))) return; + + await AccountHelper().signOut(); + + Navigator.pushReplacement(context, MaterialPageRoute(builder: (c){ + return LoginRoute(); + })); + } } diff --git a/lib/ui/screens/menus_screen.dart b/lib/ui/screens/menus_screen.dart deleted file mode 100644 index 66c3db2..0000000 --- a/lib/ui/screens/menus_screen.dart +++ /dev/null @@ -1,74 +0,0 @@ -import 'package:comunic/helpers/account_helper.dart'; -import 'package:comunic/ui/routes/login_route.dart'; -import 'package:comunic/ui/tiles/menu_tile.dart'; -import 'package:comunic/utils/account_utils.dart'; -import 'package:comunic/utils/intl_utils.dart'; -import 'package:comunic/utils/navigation_utils.dart'; -import 'package:flutter/material.dart'; - -/// Menu screen -/// -/// @author Pierre HUBERT - -class MenuScreen extends StatelessWidget { - /// Ask the user if he really wants to sign out from the application - Future _confirmSignOut(BuildContext context) async { - final result = await showDialog( - context: context, - builder: (c) { - return AlertDialog( - title: Text(tr("Confirm sign out")), - content: Text( - tr("Do your really want to sign out from the application ?")), - actions: [ - FlatButton( - child: Text(tr("Cancel").toUpperCase()), - onPressed: () { - Navigator.pop(context, false); - }, - ), - FlatButton( - child: Text( - tr("Sign out").toUpperCase(), - style: TextStyle(color: Colors.red), - ), - onPressed: () { - Navigator.pop(context, true); - }, - ), - ], - ); - }, - ); - - if(result == null || !result) - return; - - await AccountHelper().signOut(); - - Navigator.pushReplacement(context, MaterialPageRoute(builder: (c){ - return LoginRoute(); - })); - - } - - @override - Widget build(BuildContext context) { - return ListView( - children: [ - MenuTile( - title: tr("My page"), - onTap: () { - openUserPage(context: context, userID: userID()); - }, - ), - MenuTile( - title: tr("Sign out"), - onTap: () { - _confirmSignOut(context); - }, - ) - ], - ); - } -} diff --git a/lib/ui/tiles/custom_bottom_navigation_bar_item.dart b/lib/ui/tiles/custom_bottom_navigation_bar_item.dart deleted file mode 100644 index b6d496a..0000000 --- a/lib/ui/tiles/custom_bottom_navigation_bar_item.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:flutter/material.dart'; - -/// Custom navigation bar item -/// -/// @author Pierre HUBERT - -class CustomNavigationBarItem extends BottomNavigationBarItem { - const CustomNavigationBarItem({ - @required Widget icon, - Widget title, - bool selected, - }) : super(icon: icon, title: title, backgroundColor: Colors.blue,); -}