mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +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
 | 
					/// @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 {}
 | 
					mixin MainRoute implements StatefulWidget {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Public interface of home controller
 | 
					/// Public interface of home controller
 | 
				
			||||||
mixin MainController implements State<MainRoute> {
 | 
					mixin MainController implements State<MainRoute> {
 | 
				
			||||||
  /// Get current instance of Home controller
 | 
					  /// Get current instance of Home controller
 | 
				
			||||||
  static MainController of(BuildContext context) =>
 | 
					  static MainController of(BuildContext context) {
 | 
				
			||||||
      context.findAncestorStateOfType<MainController>();
 | 
					    assert(context != null); // A future implementation might need context again
 | 
				
			||||||
 | 
					    return mainControllerKey.currentState;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Open user page
 | 
					  /// Open user page
 | 
				
			||||||
  void openUserPage(int userID);
 | 
					  void openUserPage(int userID);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,8 @@ import '../login_route.dart';
 | 
				
			|||||||
/// @author Pierre HUBERT
 | 
					/// @author Pierre HUBERT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SmartphoneMainRoute extends StatefulWidget implements MainRoute {
 | 
					class SmartphoneMainRoute extends StatefulWidget implements MainRoute {
 | 
				
			||||||
 | 
					  const SmartphoneMainRoute({Key key}) : super(key: key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
  State<StatefulWidget> createState() => _MainRouteState();
 | 
					  State<StatefulWidget> createState() => _MainRouteState();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,6 +11,8 @@ import 'package:flutter/material.dart';
 | 
				
			|||||||
/// @author Pierre Hubert
 | 
					/// @author Pierre Hubert
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TabletRoute extends StatefulWidget implements MainRoute {
 | 
					class TabletRoute extends StatefulWidget implements MainRoute {
 | 
				
			||||||
 | 
					  const TabletRoute({Key key}) : super(key: key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
  _TabletRouteState createState() => _TabletRouteState();
 | 
					  _TabletRouteState createState() => _TabletRouteState();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
import 'package:comunic/helpers/events_helper.dart';
 | 
					import 'package:comunic/helpers/events_helper.dart';
 | 
				
			||||||
import 'package:comunic/helpers/websocket_helper.dart';
 | 
					import 'package:comunic/helpers/websocket_helper.dart';
 | 
				
			||||||
import 'package:comunic/ui/routes/login_route.dart';
 | 
					import 'package:comunic/ui/routes/login_route.dart';
 | 
				
			||||||
 | 
					import 'package:comunic/ui/routes/main_route/main_route.dart';
 | 
				
			||||||
import 'package:comunic/ui/routes/main_route/smartphone_route.dart';
 | 
					import 'package:comunic/ui/routes/main_route/smartphone_route.dart';
 | 
				
			||||||
import 'package:comunic/ui/routes/main_route/tablet_route.dart';
 | 
					import 'package:comunic/ui/routes/main_route/tablet_route.dart';
 | 
				
			||||||
import 'package:comunic/ui/widgets/safe_state.dart';
 | 
					import 'package:comunic/ui/widgets/safe_state.dart';
 | 
				
			||||||
@@ -77,7 +78,9 @@ class _InitializeWidgetState extends SafeState<InitializeWidget> {
 | 
				
			|||||||
  @override
 | 
					  @override
 | 
				
			||||||
  Widget build(BuildContext context) {
 | 
					  Widget build(BuildContext context) {
 | 
				
			||||||
    return !_error && WebSocketHelper.isConnected()
 | 
					    return !_error && WebSocketHelper.isConnected()
 | 
				
			||||||
        ? (isTablet(context) ? TabletRoute() : SmartphoneMainRoute())
 | 
					        ? (isTablet(context)
 | 
				
			||||||
 | 
					            ? TabletRoute(key: mainControllerKey)
 | 
				
			||||||
 | 
					            : SmartphoneMainRoute(key: mainControllerKey))
 | 
				
			||||||
        : _buildNonReadyWidget();
 | 
					        : _buildNonReadyWidget();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user