I have BottomNavigationBar using IndexedStack so that my googleMaps wont reload when changing page. In page one I have a button and on page two I have googleMaps. When I push the button I want the page to change to page two and then to call function in there. For example to zoom to new location.
I'm using scoped model to handle my state.
I have already figured out a way to change the page, but I'm not sure what to do with the GoogleMapsController. I lifted it to ScopedModel class, but now I'm getting error when opening new route and closing it and then trying to change push the button to go to a location on the map:
I/flutter ( 8784): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter ( 8784): The following NoSuchMethodError was thrown while handling a gesture:
I/flutter ( 8784): The method 'animateCamera' was called on null.
I/flutter ( 8784): Receiver: null
I/flutter ( 8784): Tried calling: animateCamera(Instance of 'CameraUpdate')
I/flutter ( 8784):
I/flutter ( 8784): When the exception was thrown, this was the stack:
I/flutter ( 8784): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
I/flutter ( 8784): #1 AppStateModel.goToMapLocation
package:restapoints/state/app_state.dart:57
I/flutter ( 8784): #2 RestaurantInfoPageState.build.<anonymous closure>.<anonymous closure>
package:restapoints/pages/restaurant_page.dart:56
I/flutter ( 8784): #3 _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:507
I/flutter ( 8784): #4 _InkResponseState.build.<anonymous closure>
package:flutter/…/material/ink_well.dart:562
I/flutter ( 8784): #5 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:102
I/flutter ( 8784): #6 TapGestureRecognizer._checkUp
package:flutter/…/gestures/tap.dart:242
I/flutter ( 8784): #7 TapGestureRecognizer.acceptGesture
package:flutter/…/gestures/tap.dart:204
I/flutter ( 8784): #8 GestureArenaManager.sweep
package:flutter/…/gestures/arena.dart:156
I/flutter ( 8784): #9 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent
package:flutter/…/gestures/binding.dart:184
I/flutter ( 8784): #10 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent
package:flutter/…/gestures/binding.dart:158
I/flutter ( 8784): #11 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent
package:flutter/…/gestures/binding.dart:138
I/flutter ( 8784): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue
package:flutter/…/gestures/binding.dart:101
I/flutter ( 8784): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket
package:flutter/…/gestures/binding.dart:85
I/flutter ( 8784): #14 _invoke1 (dart:ui/hooks.dart:168:13)
I/flutter ( 8784): #15 _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)
I/flutter ( 8784):
I/flutter ( 8784): Handler: onTap
I/flutter ( 8784): Recognizer:
I/flutter ( 8784): TapGestureRecognizer#5de3a(debugOwner: GestureDetector, state: ready, won arena, finalPosition:
I/flutter ( 8784): Offset(320.8, 298.5), sent tap down)
I/flutter ( 8784): ════════════════════════════════════════════════════════════════════════════════════════════════════
Thank you!
read about initState()
This is the first method called when the widget is created, it must be StatefullWidget
#override
void initState() {
// You can call your zooom to new location function here
super.initState();
}
This error was resolved by moving the ScopedModel to the top of Widget tree:
AppStateModel model = AppStateModel();
runApp(
ScopedModel<AppStateModel>(
model: model,
child: MaterialApp(
home: HomeWidget(),
),
),
);
So for anybody having trouble with googlemaps reloading in tabNav, use Indexed stack and wrap all the pages to Navigator. Then lift GooglemapsController to ScopedModel and put the ScopedModel(or any other state management model) to the root of your application.
Related
Using Provider and FutureBuilder, I just deleted data from database, it got removed at the same time, it shows a red screen with bad state no element. There is no problem to add data, do not show this problem.
Code is given below
stacktrace
ter (12519): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (12519): The following StateError was thrown building ViewNoteScreen(dirty, dependencies:
I/flutter (12519): [_ModalScopeStatus], state: _ViewNoteScreenState#f589b):
I/flutter (12519): Bad state: No element
I/flutter (12519):
I/flutter (12519): The relevant error-causing widget was:
I/flutter (12519): ViewNoteScreen file:///C:/Users/Admin/Desktop/daily%2010/provider_note/lib/main.dart:21:46
I/flutter (12519):
I/flutter (12519): When the exception was thrown, this was the stack:
I/flutter (12519): #0 ListMixin.firstWhere (dart:collection/list.dart:148:5)
I/flutter (12519): #1 Providers.findById (package:provider_note/helper/provider.dart:14:19)
I/flutter (12519): #2 _ViewNoteScreenState.build (package:provider_note/screens/view_note.dart:21:35)
I/flutter (12519): #3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4663:28)
I/flutter (12519): #4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4546:15)
I/flutter (12519): #5 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)
I/flutter (12519): #6 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
I/flutter (12519): #7 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2667:33)
I/flutter (12519): #8 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:866:20)
I/flutter (12519): #9 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
I/flutter (12519): #10 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
I/flutter (12519): #11 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1056:9)
I/flutter (12519): #12 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:972:5)
I/flutter (12519): #16 _invoke (dart:ui/hooks.dart:253:10)
I/flutter (12519): #17 _drawFrame (dart:ui/hooks.dart:211:3)
I/flutter (12519): (elided 3 frames from dart:async)
I/flutter (12519):
I/flutter (12519): ══════════════════════════════════════════════
BadStateException occurred when list don't contain the item and still someone searching for that
Example:
If orElse not defined in the code and the wrong item gets search which doesn't exist in the list then it shows BadStateException
void main() {
List<String> list = ['red', 'yellow', 'pink', 'blue'];
var newList = list.firstWhere((element) => element.contains('green'));
print(newList);
}
Output:
Uncaught Error: Bad state: No element
Solution: Add orElse
void main() {
List<String> list = ['red', 'yellow', 'pink', 'blue'];
var newList = list.firstWhere((element) => element.contains(''),
orElse: () => 'No matching color found');
print(newList);
}
Output:
No matching color found
I think the easiest way for you is change your home to statefull widget and change this part of your code.
Navigator.pushNamed(
context, ViewNoteScreen.routeName,
arguments: notes.items[i].id).whenComplete(() {
setState(() {});
});
I have just started learning app development via Flutter. I ran into a tutorial to build a simple app.
My task is to add appbar and I did this:
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Hello '),
),
),
));
}
I am expecting a simple app bar with the title "Hello ".
I get this error in console :
-I/flutter (17741): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (17741): The following assertion was thrown building MyApp:
I/flutter (17741): MediaQuery.of() called with a context that does not contain a MediaQuery.
I/flutter (17741): No MediaQuery ancestor could be found starting from the context that was passed to MediaQuery.of().
I/flutter (17741): This can happen because you do not have a WidgetsApp or MaterialApp widget (those widgets introduce
I/flutter (17741): a MediaQuery), or it can happen if the context you use comes from a widget above those widgets.
I/flutter (17741): The context used was:
I/flutter (17741): Scaffold
I/flutter (17741):
I/flutter (17741): The relevant error-causing widget was:
I/flutter (17741): MyApp file:///E:/Flutter/i_am_rich/lib/main.dart:3:23
I/flutter (17741):
I/flutter (17741): When the exception was thrown, this was the stack:
I/flutter (17741): #0 MediaQuery.of (package:flutter/src/widgets/media_query.dart:798:5)
I/flutter (17741): #1 ScaffoldState.didChangeDependencies (package:flutter/src/material/scaffold.dart:1993:50)
I/flutter (17741): #2 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4376:12)
I/flutter (17741): #3 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (17741): #4 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (17741): #5 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (17741): #6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
Reloaded 1 of 478 libraries in 437ms.
I/flutter (17741): #7 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (17741): #8 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2432:33)
I/flutter (17741): #9 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:773:20)
I/flutter (17741): #10 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
I/flutter (17741): #11 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
I/flutter (17741): #12 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
I/flutter (17741): #13 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:850:7)
I/flutter (17741): #15 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:384:19)
I/flutter (17741): #16 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5)
I/flutter (17741): #17 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
I/flutter (17741): (elided one frame from package dart:async-patch)
I/flutter (17741):
I/flutter (17741):
════════════════════════════════════════════════════════════════════════════════════════════════════
It would be great if you could provide me some insights into this.
Issue was solved on suggestion of #VirenVVarasadiya by running:
flutter clean
flutter run
I upgraded flutter and and run my app, but it won't start and throws invalid arguments error.
I tried switching from dev and master channels and run flutter doctor on the terminal, but problem persists.
Running "flutter pub get" in feedback... 1.0s
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
Syncing files to device Android SDK built for x86...
I/flutter ( 6956): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 6956): The following ArgumentError was thrown attaching to the render tree:
I/flutter ( 6956): Invalid argument(s)
I/flutter ( 6956): When the exception was thrown, this was the stack:
I/flutter ( 6956): #0 _StringBase.+ (dart:core-patch/string_patch.dart:260:57)
I/flutter ( 6956): #1 new _MainModel&Model&AuthModel&ResponsesModel (package:Feedback/scoped-models/main.dart:10:57)
I/flutter ( 6956): #2 new _MainModel&Model&AuthModel&ResponsesModel&UtilityModel (package:Feedback/scoped-models/main.dart)
I/flutter ( 6956): #3 new _MainModel&Model&AuthModel&ResponsesModel&UtilityModel&InternetModel (package:Feedback/scoped-models/main.dart)
I/flutter ( 6956): #4 new MainModel (package:Feedback/scoped-models/main.dart)
I/flutter ( 6956): #5 new MyAppState (package:Feedback/main.dart:23:27)
I/flutter ( 6956): #6 MyApp.createState (package:Feedback/main.dart:18:12)
I/flutter ( 6956): #7 new StatefulElement (package:flutter/src/widgets/framework.dart:3989:25)
I/flutter ( 6956): #8 StatefulWidget.createElement (package:flutter/src/widgets/framework.dart:802:38)
I/flutter ( 6956): #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3082:40)
I/flutter ( 6956): #10 Element.updateChild (package:flutter/src/widgets/framework.dart:2887:12)
I/flutter ( 6956): #11 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:939:16)
I/flutter ( 6956): #12 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:910:5)
I/flutter ( 6956): #13 RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:856:17)
I/flutter ( 6956): #14 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2320:19)
I/flutter ( 6956): #15 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:855:13)
I/flutter ( 6956): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:736:7)
I/flutter ( 6956): #17 runApp (package:flutter/src/widgets/binding.dart:786:7)
I/flutter ( 6956): #18 main (package:Feedback/main.dart:12:16)
I/flutter ( 6956): #19 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:216:25)
I/flutter ( 6956): #24 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:208:5)
I/flutter ( 6956): #25 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
I/flutter ( 6956): #26 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
I/flutter ( 6956): (elided 4 frames from package dart:async)
I/flutter ( 6956): ════════════════════════════════════════════════════════════════════════════════════════════════════
D/EGL_emulation( 6956): eglMakeCurrent: 0xaa442fc0: ver 3 0 (tinfo 0x9fb5e310)
As what have previously pointed out in the comments, running flutter clean has been suggested because it usually solves build issues. The command clears the build cache of the project and trying to run the app again should rebuild the project and potentially clears out any issues. But in this case, it seems that you've found the cause is something else.
Going forward, it will also be helpful to provide a minimal repro for folks to be able to replicate the given issue.
I am Trying to write a code for my project which uses a TabBarView with 4 tabs and has a Global Key so that I can Use the Tab controller anywhere in the app,
however when I tried to Call the animateTo Function using an onpressed Function of Raised Button It Keeps Throwing Errors as follows:
Have Already Done This://Tried Creating a function in the same file as the controller to change the view
class MyTabsState extends State<MyTabs> with SingleTickerProviderStateMixin {
static final homePageKey=GlobalKey<MyTabsState>();
TabController tabcontroller;
#override
void initState() {
super.initState();
tabcontroller = new TabController(vsync: this, length: 4);
}
#override
void dispose() {
super.dispose();
tabcontroller.dispose();
}
#override
Widget build(BuildContext context) {
return new Scaffold(
key: homePageKey,
bottomNavigationBar: new Material(
color: mainUiColor,
child: new TabBar(
controller: tabcontroller,
unselectedLabelColor: Colors.grey,
labelColor: Colors.redAccent,
tabs: <Tab>[
new Tab(icon: new Icon(Icons.home)),
new Tab(icon: new Icon(Icons.photo_album)),
new Tab(icon: new Icon(Icons.arrow_back)),
new Tab(icon: new Icon(Icons.favorite)),
])),
body: new TabBarView(controller: tabcontroller, children: <Widget>[
new First(),
new PhotoGallery(),
new Third(),
new SocialMedia(),
]),
);
}
void changePage(){
tabcontroller.animateTo(2);
}
}
I/flutter ( 4993): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════ I/flutter ( 4993): The following NoSuchMethodError was thrown while handling a gesture: I/flutter ( 4993): The method 'changePage' was called on null. I/flutter ( 4993): Receiver: null I/flutter ( 4993): Tried calling: changePage() I/flutter ( 4993): I/flutter ( 4993): When the exception was thrown, this was the stack: I/flutter ( 4993): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5) I/flutter ( 4993): #1 _PhotoGalleryState.build.<anonymous closure> (package:myproject/screenTabs/SecondTab.dart:97:52) I/flutter ( 4993):
#2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:511:14) I/flutter ( 4993):
#3 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:566:30) I/flutter ( 4993):
#4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:166:24) I/flutter ( 4993): #5 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:240:9) I/flutter ( 4993): #6 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:211:7) I/flutter ( 4993): #7 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27) I/flutter ( 4993): #8
_WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:225:20) I/flutter ( 4993):
#9 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:199:22) I/flutter ( 4993):
#10 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7) I/flutter ( 4993):
#11 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7) I/flutter ( 4993):
#12 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7) I/flutter ( 4993):
#16 _invoke1 (dart:ui/hooks.dart:233:10) I/flutter ( 4993): #17 _dispatchPointerDataPacket (dart:ui/hooks.dart:154:5) I/flutter ( 4993): (elided 3 frames from package dart:async) I/flutter ( 4993): I/flutter ( 4993): Handler: onTap I/flutter ( 4993): Recognizer: I/flutter ( 4993): TapGestureRecognizer#bfc40(debugOwner: GestureDetector, state: ready, won arena, finalPosition: I/flutter ( 4993): Offset(126.9, 667.6), sent tap down)
If I were a betting man I'd bet you may be trying to call changePage() on one of the pages listed in your tabBarView. A global key doesn't really make the item available anywhere in the app, you'd have to store it somewhere higher up in the widget tree using an inherited widget or pass it down to its children as a property in order to actually use it. It looks like something you may want to consider looking into is a CupertinoTabScaffold. Then you could wrap that around the main views, and work with it there and have it show up across the entire app. This might be a bit easier than using the current setup.
I have a splash screen and a StreamBuilder that emits a state that contains information about authentication status. When the authentication status is known, I want to navigate either to sign in page or home page. But when I write something like Navigator.of(context).pushReplacement(...) I get
I/flutter ( 2058): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 2058): The following assertion was thrown building StreamBuilder(dirty, state:
I/flutter ( 2058): _StreamBuilderBaseState>#f4346):
I/flutter ( 2058): setState() or markNeedsBuild() called during build.
I/flutter ( 2058): This Overlay widget cannot be marked as needing to build because the framework is already in the
I/flutter ( 2058): process of building widgets. A widget can be marked as needing to be built during the build phase
I/flutter ( 2058): only if one of its ancestors is currently building. This exception is allowed because the framework
I/flutter ( 2058): builds parent widgets before children, which means a dirty descendant will always be built.
I/flutter ( 2058): Otherwise, the framework might not visit this widget during this build phase.
I/flutter ( 2058): The widget on which setState() or markNeedsBuild() was called was:
I/flutter ( 2058): Overlay-[LabeledGlobalKey#e0460](state: OverlayState#ab1a5(entries:
I/flutter ( 2058): [OverlayEntry#4e962(opaque: false; maintainState: false), OverlayEntry#7656a(opaque: false;
I/flutter ( 2058): maintainState: true), OverlayEntry#1f86e(opaque: false; maintainState: false),
I/flutter ( 2058): OverlayEntry#05a15(opaque: false; maintainState: true)]))
I/flutter ( 2058): The widget which was currently being built when the offending call was made was:
I/flutter ( 2058): StreamBuilder(dirty, state: _StreamBuilderBaseState>#f4346)
I/flutter ( 2058):
I/flutter ( 2058): When the exception was thrown, this was the stack:
I/flutter ( 2058): #0 Element.markNeedsBuild. (package:flutter/src/widgets/framework.dart:3503:11)
I/flutter ( 2058): #1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:3529:6)
I/flutter ( 2058): #2 State.setState (package:flutter/src/widgets/framework.dart:1133:14)
I/flutter ( 2058): #3 OverlayState.insertAll (package:flutter/src/widgets/overlay.dart:346:5)
I/flutter ( 2058): #4 OverlayRoute.install (package:flutter/src/widgets/routes.dart:43:24)
I/flutter ( 2058): #5 TransitionRoute.install (package:flutter/src/widgets/routes.dart:180:11)
I/flutter ( 2058): #6 ModalRoute.install (package:flutter/src/widgets/routes.dart:895:11)
I/flutter ( 2058): #7 NavigatorState.pushReplacement (package:flutter/src/widgets/navigator.dart:1799:14)
I/flutter ( 2058): #8 _replace (package:map_chat/application/navigation.dart:75:27)
I/flutter ( 2058): #9 _SignInPage.replace (package:map_chat/application/navigation.dart:67:5)
I/flutter ( 2058): #10 Roadmap.replace (package:map_chat/application/navigation.dart:25:18)
I/flutter ( 2058): #11 _SplashPageState._buildPageBasedOnAuthenticationState (package:map_chat/feature/splash.dart:52:19)
I/flutter ( 2058): #12 _SplashPageState._buildSplashScreen (package:map_chat/feature/splash.dart:40:11)
I/flutter ( 2058): #13 _SplashPageState._buildPage. (package:map_chat/feature/splash.dart:27:18)
I/flutter ( 2058): #14 StreamBuilder.build (package:flutter/src/widgets/async.dart:425:74)
I/flutter ( 2058): #15 _StreamBuilderBaseState.build (package:flutter/src/widgets/async.dart:125:48)
I/flutter ( 2058): #16 StatefulElement.build (package:flutter/src/widgets/framework.dart:3825:27)
I/flutter ( 2058): #17 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3739:15)
I/flutter ( 2058): #18 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 2058): #19 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2278:33)
I/flutter ( 2058): #20 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:700:20)
I/flutter ( 2058): #21 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
I/flutter ( 2058): #22 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15)
I/flutter ( 2058): #23 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:952:9)
I/flutter ( 2058): #24 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame. (package:flutter/src/scheduler/binding.dart:773:7)
I/flutter ( 2058): #33 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
I/flutter ( 2058): #34 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
I/flutter ( 2058): #35 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:171:12)
I/flutter ( 2058): (elided 8 frames from package dart:async and package dart:async-patch)
The only workaround I found is to schedule the navigation to the end of event queue using Future(...).then(navigate) but that's sick. Is here an adequate solution for this?
You can listen your stream outside of build method and redirect to another view from there.
---- EDITED ----
This is an example of how you can do that:
#override
void initState() {
super.initState();
Future.delayed(Duration.zero, _verify);
}
void _verify() {
final _myBloc = BlocProvider.getBloc<MyBloc>();
_myBloc.myStream.listen((data) {
// Redirect to another view, given your condition
if (data) {
Navigator.of(context).pushNamed("my-new-route");
}
});
}
Just remember to save the StreamSubscription object returned from listen method, so you can cancel the subscription on dispose().
I still not happy with my solution, but I use a
if(snapshot.hasdata && snapshot.data.navigate) {
Future.microtask(() => Navigator.of(context).push... );
}