mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-26 06:49:22 +00:00
Use a key for main controller
This commit is contained in:
parent
6d95d5f7a2
commit
4367dcc728
@ -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();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:comunic/helpers/events_helper.dart';
|
||||
import 'package:comunic/helpers/websocket_helper.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/tablet_route.dart';
|
||||
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||
@ -77,7 +78,9 @@ class _InitializeWidgetState extends SafeState<InitializeWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return !_error && WebSocketHelper.isConnected()
|
||||
? (isTablet(context) ? TabletRoute() : SmartphoneMainRoute())
|
||||
? (isTablet(context)
|
||||
? TabletRoute(key: mainControllerKey)
|
||||
: SmartphoneMainRoute(key: mainControllerKey))
|
||||
: _buildNonReadyWidget();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user