mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Clean code
This commit is contained in:
		@@ -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/conversations_list_screen.dart';
 | 
				
			||||||
import 'package:comunic/ui/screens/friends_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/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/ui/widgets/navbar_widget.dart';
 | 
				
			||||||
import 'package:comunic/utils/intl_utils.dart';
 | 
					import 'package:comunic/utils/intl_utils.dart';
 | 
				
			||||||
 | 
					import 'package:comunic/utils/ui_utils.dart';
 | 
				
			||||||
import 'package:flutter/material.dart';
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import 'login_route.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Main route of the application
 | 
					/// Main route of the application
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
/// @author Pierre HUBERT
 | 
					/// @author Pierre HUBERT
 | 
				
			||||||
@@ -38,8 +40,16 @@ class _HomeRouteState extends State<HomeRoute> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  /// Handles a new tab being tapped
 | 
					  /// Handles a new tab being tapped
 | 
				
			||||||
  void _onTap(BarCallbackActions action) {
 | 
					  void _onTap(BarCallbackActions action) {
 | 
				
			||||||
    if (_currTab != action) history.add(action);
 | 
					    /// Check more quick actions
 | 
				
			||||||
    _changeTab(action);
 | 
					    switch (action) {
 | 
				
			||||||
 | 
					      case BarCallbackActions.ACTION_LOGOUT:
 | 
				
			||||||
 | 
					        _logoutRequested();
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      default:
 | 
				
			||||||
 | 
					        if (_currTab != action) history.add(action);
 | 
				
			||||||
 | 
					        _changeTab(action);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
@@ -86,4 +96,18 @@ class _HomeRouteState extends State<HomeRoute> {
 | 
				
			|||||||
      ),
 | 
					      ),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /// Handle logout requests from user
 | 
				
			||||||
 | 
					  Future<void> _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();
 | 
				
			||||||
 | 
					    }));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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<void> _confirmSignOut(BuildContext context) async  {
 | 
					 | 
				
			||||||
    final result = await showDialog<bool>(
 | 
					 | 
				
			||||||
      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: <Widget>[
 | 
					 | 
				
			||||||
            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: <Widget>[
 | 
					 | 
				
			||||||
        MenuTile(
 | 
					 | 
				
			||||||
          title: tr("My page"),
 | 
					 | 
				
			||||||
          onTap: () {
 | 
					 | 
				
			||||||
            openUserPage(context: context, userID: userID());
 | 
					 | 
				
			||||||
          },
 | 
					 | 
				
			||||||
        ),
 | 
					 | 
				
			||||||
        MenuTile(
 | 
					 | 
				
			||||||
          title: tr("Sign out"),
 | 
					 | 
				
			||||||
          onTap: () {
 | 
					 | 
				
			||||||
            _confirmSignOut(context);
 | 
					 | 
				
			||||||
          },
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
      ],
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -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,);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user