-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Easily navigate, show dialogs, menus, bottom sheets and scaffold outside the widget tree without BuildContext [New UPDATA] #129
Comments
Hi, I started using RM.navigate.toReplacement() and figured out that after navigating to another page the registered models are gone.
Main widgetMaterialApp(
title: 'Lumber-dev',
theme: ThemeData(
primarySwatch: Colors.grey,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
navigatorKey: RM.navigate.navigatorKey,
home: Injector(
inject: [
Inject.future(() => Firebase.initializeApp()),
Inject<CameraService>(() => CameraService()),
Inject<LumberService>(() => LumberService()),
],
disposeModels: true,
builder: (context) {
return WhenRebuilder<FirebaseApp>(
key: Key('MAIN_KEY'),
observe: () => RM.get<FirebaseApp>(),
onWaiting: () => LinearProgressIndicator(),
onIdle: () => Text('Idle'),
onError: (error) => Text('Error'),
onData: (data) {
//freturn AddLumberScreen();
return LumberListScreen();
//return Text('fefefe');
},
);
},
),
);, I Inject the models at the beginning of the main widget. The other widgets use WhenRebuilderOr class to get data. With RM.navigate.to() the models are stil registered but it seems that the models are not disposed of, and after coming back it reruns my initState multiple times.
Am I doing something wrong? |
Models that you do not want them to dispose of after navigation, inject them above the MaterialApp widget. Try to inject CameraService abovethe MaterialApp and see! |
I am using FCM for push notification. onResume and onMessage (while app is open or in background) handler does proper navigation to a page but onLaunch (after completely exiting the app) shows homepage instead of the desired page.
and
Am I doing it wrong? Is there other way to do this? |
I checked log and onLaunch is triggering _serialiseAndNavigate() with correct data, but is not navigating to correct destination. Other ways to achieve this? |
Finally I got some log,
But I already have
|
It worked after using
directly inside onLaunch. Problem is solved. State Rebuilder is awesome. |
With
states_rebuilder
, you can perform side effects that require a BuildContext without being forced to be in the widget tree.In order for states_rebuilder to navigate and display dialogs without a
BuildContext
, we need to set thenavigatorKey
of theMaterialApp
widget and assign it toRM.navigate.navigatorKey
.Navigation
states_rebuilder follows the naming convention as in Flutter SDK, with one minor change:
push
becomesto
in states_rebuilder.pop
becomesback
in states_rebuilder.1- push a route:
2- push a named route:
3- push a route and replace the current one:
4- push a route and replace the current one:
5- push a route and remove util the route of the given name:
6- push named route and remove util the route of the given name:
7- pop a route:
8- pop all routes until we reach a previous route name:
9- pop the current route and push to a named route:
10- For any other navigation option, you can use the navigatorState exposed by states_rebuilder:
example:
Dialogs and Sheets
Dialogs when displayed are pushed into the route stack. It is for this reason, in states_rebuilder, dialogs are treated as navigation:
In Flutter to show a dialog:
In states_rebuilder to show a dialog:
For sure, states_rebuilder is less boilerplate, but it is also more intuitive.
In states_rebuilder we make it clear that we are navigating to the dialog, so to close a dialog, we just pop it from the route stack.
So states_rebuilder follows the naming convention as in Flutter SDK, with the change from
show
in Flutter toto
in states_rebuilder.1- Show a material dialog:
2- Show a cupertino dialog:
3- Show a cupertino dialog:
4- Show a cupertino dialog:
5- For all other dialogs, menus, bottom sheets, not mentioned here, you can use is as defined by flutter using
RM.context
:example:
Show bottom sheets, snackBars and drawers that depend on the scaffolding
Some side effects require a BuildContext of a scaffold child widget.
In state_states_rebuilder to be able to display them outside the widget tree without explicitly specifying the BuildContext, we need to tell states_rebuild which BuildContext to use first.
This can be done either:
Or
If you have one of the states_rebuilder widgets that is a child of the
Scaffold
, you no longer need to specify aBuildContext
. TheBuildContext
of this widget will be used.Since
SnackBars
, for example, depend onScaffoldState
and aren't pushed to the route stack, we don't treat them as navigation like we did with dialogs.To distinguish them from Dialogs and to emphasize that they need a Scaffold-related
BuildContext
, we useRM.scaffoldShow
instead ofRM.navigate
.1- Show a persistent bottom sheet:
2- Show a snackBar:
3- Open a drawer:
4- Open a end drawer:
5- For anything, not mentioned here, you can use the scaffoldState exposed by states_rebuilder.
The text was updated successfully, but these errors were encountered: