Skip to content
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

ScreenObserver not working with nested navigation #30

Open
t-unit opened this issue Sep 29, 2023 · 6 comments
Open

ScreenObserver not working with nested navigation #30

t-unit opened this issue Sep 29, 2023 · 6 comments

Comments

@t-unit
Copy link
Contributor

t-unit commented Sep 29, 2023

Trying to use ScreenObserver will raise following error when using it with nested routers:

'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3362 pos 14: 'observer.navigator == null': is not true.

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building Builder:
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3362 pos 14: 'observer.navigator == null': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.yml

The relevant error-causing widget was
Router
When the exception was thrown, this was the stack
#2 NavigatorState.initState
#3 StatefulElement._firstBuild
#4 ComponentElement.mount
... Normal element mounting (41 frames)
#45 _InheritedProviderScopeElement.mount
... Normal element mounting (7 frames)
#52 SingleChildWidgetElementMixin.mount
#53 Element.inflateWidget
#54 Element.updateChild
#55 SingleChildRenderObjectElement.update
#56 Element.updateChild
#57 ComponentElement.performRebuild
#58 Element.rebuild
#59 StatelessElement.update
#60 Element.updateChild
#61 SingleChildRenderObjectElement.update
#62 Element.updateChild
#63 SingleChildRenderObjectElement.update
#64 Element.updateChild
#65 ComponentElement.performRebuild
#66 StatefulElement.performRebuild
#67 Element.rebuild
#68 StatefulElement.update
#69 Element.updateChild
#70 SingleChildRenderObjectElement.update
#71 Element.updateChild
#72 ComponentElement.performRebuild
#73 StatefulElement.performRebuild
#74 Element.rebuild
#75 StatefulElement.update
#76 Element.updateChild
#77 SingleChildRenderObjectElement.update
#78 Element.updateChild
#79 ComponentElement.performRebuild
#80 StatefulElement.performRebuild
#81 Element.rebuild
#82 StatefulElement.update
#83 Element.updateChild
#84 ComponentElement.performRebuild
#85 StatefulElement.performRebuild
#86 Element.rebuild
#87 StatefulElement.update
#88 Element.updateChild
#89 SingleChildRenderObjectElement.update
#90 Element.updateChild
#91 ComponentElement.performRebuild
#92 StatefulElement.performRebuild
#93 Element.rebuild
#94 StatefulElement.update
#95 Element.updateChild
#96 SingleChildRenderObjectElement.update
#97 Element.updateChild
#98 ComponentElement.performRebuild
#99 StatefulElement.performRebuild
#100 Element.rebuild
#101 StatefulElement.update
#102 Element.updateChild
#103 ComponentElement.performRebuild
#104 StatefulElement.performRebuild
#105 Element.rebuild
#106 StatefulElement.update
#107 Element.updateChild
#108 ComponentElement.performRebuild
#109 Element.rebuild
#110 StatelessElement.update
#111 Element.updateChild
#112 ComponentElement.performRebuild
#113 StatefulElement.performRebuild
#114 Element.rebuild
#115 StatefulElement.update
#116 Element.updateChild
#117 SingleChildRenderObjectElement.update
#118 Element.updateChild
#119 ComponentElement.performRebuild
#120 Element.rebuild
#121 ProxyElement.update
#122 _InheritedNotifierElement.update
#123 Element.updateChild
#124 SingleChildRenderObjectElement.update
#125 Element.updateChild
#126 ComponentElement.performRebuild
#127 StatefulElement.performRebuild
#128 Element.rebuild
#129 StatefulElement.update
#130 Element.updateChild
#131 ComponentElement.performRebuild
#132 Element.rebuild
#133 ProxyElement.update
#134 Element.updateChild
#135 ComponentElement.performRebuild
#136 Element.rebuild
#137 ProxyElement.update
#138 Element.updateChild
#139 ComponentElement.performRebuild
#140 StatefulElement.performRebuild
#141 Element.rebuild
#142 StatefulElement.update
#143 Element.updateChild
#144 ComponentElement.performRebuild
#145 Element.rebuild
#146 StatelessElement.update
#147 Element.updateChild
#148 ComponentElement.performRebuild
#149 Element.rebuild
#150 StatelessElement.update
#151 Element.updateChild
#152 SingleChildRenderObjectElement.update
#153 Element.updateChild
#154 ComponentElement.performRebuild
#155 Element.rebuild
#156 ProxyElement.update
#157 Element.updateChild
#158 ComponentElement.performRebuild
#159 Element.rebuild
#160 ProxyElement.update
#161 Element.updateChild
#162 ComponentElement.performRebuild
#163 StatefulElement.performRebuild
#164 Element.rebuild
#165 StatefulElement.update
#166 Element.updateChild
#167 ComponentElement.performRebuild
#168 StatefulElement.performRebuild
#169 Element.rebuild
#170 StatefulElement.update
#171 Element.updateChild
#172 ComponentElement.performRebuild
#173 StatefulElement.performRebuild
#174 Element.rebuild
#175 BuildOwner.buildScope
#176 WidgetsBinding.drawFrame
#177 RendererBinding._handlePersistentFrameCallback
#178 SchedulerBinding._invokeFrameCallback
#179 SchedulerBinding.handleDrawFrame
#180 SchedulerBinding._handleDrawFrame
#184 _invoke (dart:ui/hooks.dart:172:10)
#185 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:401:5)
#186 _drawFrame (dart:ui/hooks.dart:140:31)
(elided 5 frames from class _AssertionError and dart:async)
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3362 pos 14: 'observer.navigator == null': is not true.
The relevant error-causing widget was
Router
════════════════════════════════════════════════════════════════════════════════
D/EGL_emulation(31181): app_time_stats: avg=205.08ms min=19.66ms max=857.14ms count=8
I/flutter (31181): ================ Error dispatched to Datadog ================
I/flutter (31181): 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3362 pos 14: 'observer.navigator == null': is not true.
I/flutter (31181): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
I/flutter (31181): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
I/flutter (31181): #2 NavigatorState.initState (package:flutter/src/widgets/navigator.dart:3362:14)
I/flutter (31181): #3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5430:55)
I/flutter (31181): #4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5273:5)
I/flutter (31181): #5 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4182:16)
I/flutter (31181): #6 Element.updateChild (package:flutter/src/widgets/framework.dart:3707:18)
I/flutter (31181): #7 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #8 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #9 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5279:5)
I/flutter (31181): #10 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5273:5)
I/flutter (31181): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4182:16)
I/flutter (31181): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:3707:18)
I/flutter (31181): #13 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #14 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #15 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5279:5)
I/flutter (31181): #16 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5273:5)
I/flutter (31181): #17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4182:16)
I/flutter (31181): #18 Element.updateChild (package:flutter/src/widgets/framework.dart:3707:18)
I/flutter (31181): #19 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #20 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #21 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5279:5)
I/flutter (31181): #22 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5273:5)
I/flutter (31181): #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4182:16)
I/flutter (31181): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:3707:18)
I/flutter (31181): #25 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #26 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #27 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #28 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5279:5)
I/flutter (31181): #29 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:11)
I/flutter (31181): #30 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5273:5)
I/flutter (31181): #31 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4182:16)
I/flutter (31181): #32 Element.updateChild (package:flutter/src/widgets/framework.dart:3707:18)
I/flutter (31181): #33 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #34 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #35 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #36 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5279:5)
I/flutter (31181): #37 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:11)
I/flutter (31181): #38 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5273:5)
I/flutter (31181): #39 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4182:16)
I/flutter (31181): #40 Element.updateChild (package:flutter/src/widgets/framework.dart:3707:18)
I/flutter (31181): #41 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #42 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #43 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5279:5)
I/flutter (31181): #44 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5273:5)
I/flutter (31181): #45 _InheritedProviderScopeElement.mount (package:provider/src/inherited_provider.dart:411:11)
I/flutter (31181): #46 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4182:16)
I/flutter (31181): #47 Element.updateChild (package:flutter/src/widgets/framework.dart:3707:18)
I/flutter (31181): #48 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #49 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #50 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5279:5)
I/flutter (31181): #51 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5273:5)
I/flutter (31181): #52 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
I/flutter (31181): #53 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4182:16)
I/flutter (31181): #54 Element.updateChild (package:flutter/src/widgets/framework.dart:3701:20)
I/flutter (31181): #55 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6441:14)
I/flutter (31181): #56 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #57 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #58 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #59 StatelessElement.update (package:flutter/src/widgets/framework.dart:5373:5)
I/flutter (31181): #60 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #61 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6441:14)
I/flutter (31181): #62 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #63 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6441:14)
I/flutter (31181): #64 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #65 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #66 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #67 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #68 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #69 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #70 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6441:14)
I/flutter (31181): #71 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #72 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #73 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #74 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #75 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #76 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #77 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6441:14)
I/flutter (31181): #78 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #79 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #80 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #81 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #82 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #83 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #84 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #85 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #86 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #87 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #88 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #89 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6441:14)
I/flutter (31181): #90 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #91 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #92 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #93 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #94 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #95 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #96 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6441:14)
I/flutter (31181): #97 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #98 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #99 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #100 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #101 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #102 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #103 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #104 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #105 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #106 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #107 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #108 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #109 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #110 StatelessElement.update (package:flutter/src/widgets/framework.dart:5373:5)
I/flutter (31181): #111 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #112 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #113 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #114 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #115 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #116 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #117 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6441:14)
I/flutter (31181): #118 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #119 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #120 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #121 ProxyElement.update (package:flutter/src/widgets/framework.dart:5628:5)
I/flutter (31181): #122 _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:107:11)
I/flutter (31181): #123 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #124 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6441:14)
I/flutter (31181): #125 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #126 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #127 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #128 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #129 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #130 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #131 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #132 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #133 ProxyElement.update (package:flutter/src/widgets/framework.dart:5628:5)
I/flutter (31181): #134 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #135 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #136 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #137 ProxyElement.update (package:flutter/src/widgets/framework.dart:5628:5)
I/flutter (31181): #138 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #139 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #140 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #141 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #142 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #143 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #144 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #145 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #146 StatelessElement.update (package:flutter/src/widgets/framework.dart:5373:5)
I/flutter (31181): #147 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #148 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #149 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #150 StatelessElement.update (package:flutter/src/widgets/framework.dart:5373:5)
I/flutter (31181): #151 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #152 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6441:14)
I/flutter (31181): #153 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #154 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #155 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #156 ProxyElement.update (package:flutter/src/widgets/framework.dart:5628:5)
I/flutter (31181): #157 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #158 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #159 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #160 ProxyElement.update (package:flutter/src/widgets/framework.dart:5628:5)
I/flutter (31181): #161 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #162 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #163 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #164 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #165 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #166 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #167 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #168 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #169 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #170 StatefulElement.update (package:flutter/src/widgets/framework.dart:5485:5)
I/flutter (31181): #171 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
I/flutter (31181): #172 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
I/flutter (31181): #173 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
I/flutter (31181): #174 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
I/flutter (31181): #175 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2779:19)
I/flutter (31181): #176 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:916:21)
I/flutter (31181): #177 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:360:5)
I/flutter (31181): #178 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1297:15)
I/flutter (31181): #179 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1227:9)
I/flutter (31181): #180 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1085:5)
I/flutter (31181): #181 _rootRun (dart:async/zone.dart:1399:13)
I/flutter (31181): #182 _CustomZone.run (dart:async/zone.dart:1301:19)
I/flutter (31181): #183 _CustomZone.runGuarded (dart:async/zone.dart:1209:7)
I/flutter (31181): #184 _invoke (dart:ui/hooks.dart:172:10)
I/flutter (31181): #185 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:401:5)
I/flutter (31181): #186 _drawFrame (dart:ui/hooks.dart:140:31)

The problem sees that Flutter won't allow having the same observer multiple times present in the widget tree. And since ScreenObserver() will always return the same instance, this breaks.

@edsonjab
Copy link
Contributor

edsonjab commented Oct 3, 2023

Hi @t-unit thank you for your report, we start looking into this.

@edsonjab
Copy link
Contributor

Hi @t-unit could you help us to share how you implemented your code, please?

@t-unit
Copy link
Contributor Author

t-unit commented Oct 19, 2023

@edsonjab Here is an example of nested navigation that breaks when adding your ScreenObserver. It does not make any sense, but give a good example of what I mean:

import 'package:analytics/client.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({super.key});

  final _routerDelegate = MyRouterDelegate();

  @override
  Widget build(BuildContext context) => MaterialApp.router(routerDelegate: _routerDelegate);
}

class MyRouterDelegate extends RouterDelegate<String> with ChangeNotifier, PopNavigatorRouterDelegateMixin<String> {
  MyRouterDelegate() : navigatorKey = GlobalKey<NavigatorState>();

  @override
  final GlobalKey<NavigatorState> navigatorKey;
  final _childRouterDelegate = MySubRouterDelegate();

  @override
  Widget build(BuildContext context) {
    return Navigator(
      observers: [ScreenObserver()],
      key: navigatorKey,
      pages: [MaterialPage(child: Router(routerDelegate: _childRouterDelegate))],
      onPopPage: (route, result) => false,
    );
  }

  @override
  Future<void> setNewRoutePath(String configuration) async {}
}

class MySubRouterDelegate extends RouterDelegate<String> with ChangeNotifier, PopNavigatorRouterDelegateMixin<String> {
  MySubRouterDelegate() : navigatorKey = GlobalKey<NavigatorState>();

  @override
  final GlobalKey<NavigatorState> navigatorKey;

  @override
  Widget build(BuildContext context) {
    return Navigator(
      observers: [ScreenObserver()],
      key: navigatorKey,
      pages: const [MaterialPage(child: Text('content'))],
      onPopPage: (route, result) => false,
    );
  }

  @override
  Future<void> setNewRoutePath(String configuration) async {}
}

@edsonjab
Copy link
Contributor

edsonjab commented Nov 7, 2023

Hi @t-unit sorry to answer late, looks like the issue is directly with flutter, you can check this URL, that user report the same issue directly on flutter and he found a solution to implement the navigation.

@t-unit
Copy link
Contributor Author

t-unit commented Nov 8, 2023

@edsonjab Thanks for the response, but I don't see how this is related to our issue. Neither the linked problem nor the solution do use nested navigators/routers that register navigation observers. (The proposed solution does not even register any navigation observers!)

For now we copied the the observer code from this package and adjusted it so we can create many instances and don't need to reuse the exact same instance for all places where we want to register an observer.

Another observation we made is that your current implementation is incompatible with the popular auto_route package. They also require that navigation observers are freshly created:

[...] make sure navigatorObservers builder always returns fresh observer instances.

@edsonjab
Copy link
Contributor

edsonjab commented Nov 8, 2023

Hi @t-unit I mean about the error 'observer.navigator == null': is not true.' the link that I shared explain another way to implement the navigation without observers and explain the error about observers is directly on flutter no related to 'analytics_flutter'. We still working to solve the issue that you reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants