-
Notifications
You must be signed in to change notification settings - Fork 219
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
After rebuild callbacks #55
Conversation
These allow users to run code after the build method is called the first time, and after the widget is rebuilt after the ViewModel changes
Codecov Report
@@ Coverage Diff @@
## master #55 +/- ##
==========================================
+ Coverage 98.59% 98.76% +0.17%
==========================================
Files 1 1
Lines 71 81 +10
==========================================
+ Hits 70 80 +10
Misses 1 1
Continue to review full report at Codecov.
|
thank you for your changes:) |
Sounds good! I'm currently traveling and will merge this up when I'm back in action early next week :) If you need this right away, please consider pointing your pubspec to this branch until I can publish a new version! |
Hi Brian, Thanks for the quick implementation :). flutter: ══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during a scheduler callback:
flutter: Looking up a deactivated widget's ancestor is unsafe.
flutter: At this point the state of the widget's element tree is no longer stable. To safely refer to a
flutter: widget's ancestor in its dispose() method, save a reference to the ancestor by calling
flutter: inheritFromWidgetOfExactType() in the widget's didChangeDependencies() method.
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:3203:9)
flutter: #1 Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3212:6)
flutter: #2 Element.ancestorStateOfType (package:flutter/src/widgets/framework.dart:3254:12)
flutter: #3 Navigator.of (package:flutter/src/widgets/navigator.dart:1176:19)
flutter: #4 Navigator.pushReplacementNamed (package:flutter/src/widgets/navigator.dart:684:22)
flutter: #5 SplashScreen.build.<anonymous closure> (package:sweetnest_app/containers/splash_screen.dart:23:21)
flutter: #6 _StoreStreamListenerState._init.<anonymous closure>.<anonymous closure> (package:flutter_redux/flutter_redux.dart)
flutter: #7 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
flutter: #8 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:938:9)
flutter: #9 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
flutter: #10 _invoke (dart:ui/hooks.dart:120:13)
flutter: #11 _drawFrame (dart:ui/hooks.dart:109:3)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: Looking up a deactivated widget's ancestor is unsafe. the exception is raised on a container splash screen. It's store connector looks like that: @override
Widget build(BuildContext context) {
return StoreConnector<AppState, _ViewModel>(
converter: _ViewModel.fromStore,
onInitialBuild: (_ViewModel vm) {
vm.onLaunchStarted();
},
onDidChange: (_ViewModel vm){
if(vm.initializationCompleted)
Navigator.pushReplacementNamed(context, 'home');
},
builder:...
} onLauchStarted dispatch an action that is captured by a middleware that perform all necessary initialization. Once the middleware is complete it dispatch an action that will be reduce to set a initializationCompleted flag on the appState. The flow works but I have this nasty exception... Any idea? thanks , Alex |
I moved the conditional routing to onWillChange and the exception is no more. |
Thanks for the feedback @AlexandreRoba -- I'll add that to the docs. |
This adds two callbacks to the
StoreConnector
andStoreBuilder
:onInitialBuild
-- Called after the Widget is built the first timeonDidChange
-- Called after the Widget is rebuilt when the ViewModel changes (if you usedistinct
and the ViewModel does not change, this will not be invoked).Fixes #47