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... );
}
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'm new to Flutter,
Right after creating my second app:
flutter create myapp && cd myapp && flutter run
I'm getting this exception. And although the app with the simple counter works in emulator, this exception doesn't look healthy, right?
Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib/main.dart on Android SDK built for x86 in debug mode...
I/flutter ( 6000): ══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 6000): The following assertion was thrown during a scheduler callback:
I/flutter ( 6000): There are multiple heroes that share the same tag within a subtree.
I/flutter ( 6000): Within each subtree for which heroes are to be animated (i.e. a PageRoute subtree), each Hero must
I/flutter ( 6000): have a unique non-null tag.
I/flutter ( 6000): In this case, multiple heroes had the following tag: <default FloatingActionButton tag>
...
(package:flutter/src/scheduler/binding.dart:1102:15)
I/flutter ( 6000): #141 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1049:9)
I/flutter ( 6000): #142 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)
I/flutter ( 6000): #146 _invoke (dart:ui/hooks.dart:259:10)
I/flutter ( 6000): #147 _drawFrame (dart:ui/hooks.dart:217:3)
I/flutter ( 6000): (elided 3 frames from package dart:async)
I/flutter ( 6000): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 6000): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter ( 6000): The following NetworkImageLoadException was thrown resolving an image codec:
I/flutter ( 6000): HTTP request failed, statusCode: 403,
I/flutter ( 6000): https://cdn.pixabay.com/photo/2016/04/10/21/34/woman-1320810_960_720.jpg
I/flutter ( 6000):
I/flutter ( 6000): When the exception was thrown, this was the stack:
I/flutter ( 6000): #0 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:90:9)
I/flutter ( 6000): <asynchronous suspension>
I/flutter ( 6000): #1 NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:47:14)
I/flutter ( 6000): #2 ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:327:17)
I/flutter ( 6000): #3 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:160:22)
...
(package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 6000): #213 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 6000): #214 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 6000): #215 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 6000): #216 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 6000): #217 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 6000): #218 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 6000): #219 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 6000): #220 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 6000): #221 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:163:11)
I/flutter ( 6000): #222 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:477:7)
I/flutter ( 6000): #223 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:232:7)
I/flutter ( 6000): #224 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:391:14)
I/flutter ( 6000): #225 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1584:7)
I/flutter ( 6000): #226 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:844:18)
I/flutter ( 6000): #227 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:344:19)
I/flutter ( 6000): #228 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:774:13)
I/flutter ( 6000): #229 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
I/flutter ( 6000): #230 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
I/flutter ( 6000): #231 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
I/flutter ( 6000): #232 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)
I/flutter ( 6000): #236 _invoke (dart:ui/hooks.dart:259:10)
I/flutter ( 6000): #237 _drawFrame (dart:ui/hooks.dart:217:3)
I/flutter ( 6000): (elided 6 frames from package dart:async)
I/flutter ( 6000):
I/flutter ( 6000): Image provider:
I/flutter ( 6000): NetworkImage("https://cdn.pixabay.com/photo/2016/04/10/21/34/woman-1320810_960_720.jpg", scale:
I/flutter ( 6000): 1.0)
I/flutter ( 6000): Image key: NetworkImage("https://cdn.pixabay.com/photo/2016/04/10/21/34/woman-1320810_960_720.jpg",
I/flutter ( 6000): scale: 1.0)
I/flutter ( 6000): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 6000): Another exception was thrown: There are multiple heroes that share the same tag within a subtree.
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 26.5s
✓ Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk... 8.8s
Syncing files to device Android SDK built for x86...
10,951ms (!)
Do you have any idea why? Thanks!
The starter Flutter app doesn't contain things like loading network images as it's just a simple counter app. As Vijaya said, it's probably just an old error from another project. I get the same stuff when I use flutter run. Unless you edited the flutter create template, you have nothing to worry about.
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 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.