mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Use a key for main controller
This commit is contained in:
		@@ -6,13 +6,21 @@ import 'package:flutter/material.dart';
 | 
			
		||||
///
 | 
			
		||||
/// @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<MainController>();
 | 
			
		||||
 | 
			
		||||
mixin MainRoute implements StatefulWidget {}
 | 
			
		||||
 | 
			
		||||
/// Public interface of home controller
 | 
			
		||||
mixin MainController implements State<MainRoute> {
 | 
			
		||||
  /// Get current instance of Home controller
 | 
			
		||||
  static MainController of(BuildContext context) =>
 | 
			
		||||
      context.findAncestorStateOfType<MainController>();
 | 
			
		||||
  static MainController of(BuildContext context) {
 | 
			
		||||
    assert(context != null); // A future implementation might need context again
 | 
			
		||||
    return mainControllerKey.currentState;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Open user page
 | 
			
		||||
  void openUserPage(int userID);
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,8 @@ import '../login_route.dart';
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class SmartphoneMainRoute extends StatefulWidget implements MainRoute {
 | 
			
		||||
  const SmartphoneMainRoute({Key key}) : super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  State<StatefulWidget> createState() => _MainRouteState();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,8 @@ import 'package:flutter/material.dart';
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
 | 
			
		||||
class TabletRoute extends StatefulWidget implements MainRoute {
 | 
			
		||||
  const TabletRoute({Key key}) : super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  _TabletRouteState createState() => _TabletRouteState();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user