You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The user opens the app and is presented with a loading indicator
Behind the scenes, the app makes a network request to determine the health of the system (is the backend up, what the allowed minimum version is, etc.)
Upon completion of the request, I need to do a few things
a. If the call failed, navigate to the login page (assume everything is okay) and clear the back stack. I have this working via dispatching a navigation action in the middleware.
b. If the call succeeded, do our validation and show a dialog if invalid or go to the login page if valid and clear the back stack. I'm struggling with both of these cases.
I am using the logic described here for navigation. However, I'm not quite sure how to show a dialog if the data is invalid or navigate if it is valid. I need a BuildContext in order to actually use the showDialog method which makes it problematic to do in the middleware. If I put the logic in some redux container, I get the following error on trying to show the dialog.
dialog output
Restarted application in 1,856ms.
I/flutter (20134): Instance of 'LoadHealthCheckAction'
I/flutter (20134): Instance of 'HealthCheckSuccessAction'
I/flutter (20134): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (20134): The following assertion was thrown building StreamBuilder<_ViewModel>(dirty, state:
I/flutter (20134): _StreamBuilderBaseState<_ViewModel, AsyncSnapshot<_ViewModel>>#6adf2):
I/flutter (20134): setState() or markNeedsBuild() called during build.
I/flutter (20134): This Overlay widget cannot be marked as needing to build because the framework is already in the
I/flutter (20134): process of building widgets. A widget can be marked as needing to be built during the build phase
I/flutter (20134): only if one of its ancestors is currently building. This exception is allowed because the framework
I/flutter (20134): builds parent widgets before children, which means a dirty descendant will always be built.
I/flutter (20134): Otherwise, the framework might not visit this widget during this build phase.
I/flutter (20134): The widget on which setState() or markNeedsBuild() was called was:
I/flutter (20134): Overlay-[LabeledGlobalKey<OverlayState>#56055](state: OverlayState#ad67b(entries:
I/flutter (20134): [OverlayEntry#d9200(opaque: false; maintainState: false), OverlayEntry#dba24(opaque: false;
I/flutter (20134): maintainState: true), OverlayEntry#dd974(opaque: false; maintainState: false),
I/flutter (20134): OverlayEntry#a603e(opaque: false; maintainState: true)]))
I/flutter (20134): The widget which was currently being built when the offending call was made was:
I/flutter (20134): StreamBuilder<_ViewModel>(dirty, state: _StreamBuilderBaseState<_ViewModel,
I/flutter (20134): AsyncSnapshot<_ViewModel>>#6adf2)
I/flutter (20134):
I/flutter (20134): When the exception was thrown, this was the stack:
I/flutter (20134): #0 Element.markNeedsBuild.<anonymous closure>
I/flutter (20134): #1 Element.markNeedsBuild
I/flutter (20134): #2 State.setState
I/flutter (20134): #3 OverlayState.insertAll
I/flutter (20134): #4 OverlayRoute.install
I/flutter (20134): #5 TransitionRoute.install
I/flutter (20134): #6 ModalRoute.install
I/flutter (20134): #7 NavigatorState.push
I/flutter (20134): #8 showGeneralDialog
I/flutter (20134): #9 showDialog
I/flutter (20134): #10 HealthCheckContainer.build.<anonymous closure>
I/flutter (20134): #11 _StoreStreamListenerState.build.<anonymous closure> (package:flutter_redux/flutter_redux.dart)
I/flutter (20134): #12 StreamBuilder.build
I/flutter (20134): #13 _StreamBuilderBaseState.build
I/flutter (20134): #14 StatefulElement.build
I/flutter (20134): #15 ComponentElement.performRebuild
I/flutter (20134): #16 Element.rebuild
I/flutter (20134): #17 BuildOwner.buildScope
I/flutter (20134): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame
I/flutter (20134): #19 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback
I/flutter (20134): #20 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback
I/flutter (20134): #21 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame
I/flutter (20134): #22 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame
I/flutter (20134): #23 _invoke (dart:ui/hooks.dart:159:13)
I/flutter (20134): #24 _drawFrame (dart:ui/hooks.dart:148:3)
I/flutter (20134): ════════════════════════════════════════════════════════════════════════════════════════════════════
Code
The relevant code is below. Any help is greatly appreciated.
I feel kind of silly for not noticing all the callbacks given by the store connector. Anyway, I solved it using the onDidChange callback. Here is the final code for the success case for those who are interested.
Use Case
I have the following use case:
a. If the call failed, navigate to the login page (assume everything is okay) and clear the back stack. I have this working via dispatching a navigation action in the middleware.
b. If the call succeeded, do our validation and show a dialog if invalid or go to the login page if valid and clear the back stack. I'm struggling with both of these cases.
I am using the logic described here for navigation. However, I'm not quite sure how to show a dialog if the data is invalid or navigate if it is valid. I need a
BuildContext
in order to actually use theshowDialog
method which makes it problematic to do in the middleware. If I put the logic in some redux container, I get the following error on trying to show the dialog.dialog output
Code
The relevant code is below. Any help is greatly appreciated.
app.dart
startup_screen.dart
health_check_container.dart
app_middleware.dart
health_check_state.dart
health_check_reducer.dart
The text was updated successfully, but these errors were encountered: