flutter 在Element.widget中,TypeError框架,dart

lrl1mhuk  于 3个月前  发布在  Flutter
关注(0)|答案(4)|浏览(44)

重现步骤

在Sentry中找到。似乎与我们在最新版本中使用的新Flutter版本有关。

预期结果

没有异常

实际结果

似乎只发生在iOS上

_TypeError: Null check operator used on a null value
  File "framework.dart", line 3484, in Element.widget
  File "framework.dart", line 4820, in Element.findAncestorWidgetOfExactType
  File "page_storage.dart", line 194, in PageStorage.maybeOf
  File "scroll_position.dart", line 511, in ScrollPosition.restoreScrollOffset
  File "scroll_position.dart", line 192, in new ScrollPosition
  File "scroll_position_with_single_context.dart", in new ScrollPositionWithSingleContext
  File "scroll_controller.dart", line 291, in ScrollController.createScrollPosition
  File "scrollable.dart", line 603, in ScrollableState._updatePosition
  File "scrollable.dart", line 638, in ScrollableState.didChangeDependencies
  File "framework.dart", line 5636, in StatefulElement._firstBuild
  File "framework.dart", line 5463, in ComponentElement.mount
  File "framework.dart", line 4340, in Element.inflateWidget
  File "framework.dart", line 3843, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5563, in StatelessElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5563, in StatelessElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 6776, in SingleChildRenderObjectElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5563, in StatelessElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 3976, in Element.updateChildren
  File "framework.dart", line 6929, in MultiChildRenderObjectElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5650, in StatefulElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5673, in StatefulElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5563, in StatelessElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5816, in ProxyElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5816, in ProxyElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5816, in ProxyElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5563, in StatelessElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 6776, in SingleChildRenderObjectElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 6776, in SingleChildRenderObjectElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5816, in ProxyElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 6776, in SingleChildRenderObjectElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5563, in StatelessElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 6776, in SingleChildRenderObjectElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5650, in StatefulElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5673, in StatefulElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5563, in StatelessElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 6776, in SingleChildRenderObjectElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 6776, in SingleChildRenderObjectElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 6776, in SingleChildRenderObjectElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5563, in StatelessElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 5563, in StatelessElement.update
  File "framework.dart", line 3827, in Element.updateChild
  File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild
  File "framework.dart", line 2905, in BuildOwner.buildScope
  File "binding.dart", line 1136, in WidgetsBinding.drawFrame
  File "binding.dart", line 443, in RendererBinding._handlePersistentFrameCallback
  File "binding.dart", line 1392, in SchedulerBinding._invokeFrameCallback
  File "binding.dart", line 1313, in SchedulerBinding.handleDrawFrame
  File "binding.dart", line 1171, in SchedulerBinding._handleDrawFrame
  File "zone.dart", line 1399, in _rootRun
  File "zone.dart", line 1301, in _CustomZone.run
  File "zone.dart", line 1209, in _CustomZone.runGuarded
  File "hooks.dart", line 314, in _invoke
  File "platform_dispatcher.dart", line 419, in PlatformDispatcher._drawFrame
  File "hooks.dart", line 283, in _drawFrame`

代码示例

代码示例

[Paste your code here]

截图或视频

截图/视频演示
[上传媒体在这里]

日志

日志

[Paste your logs here]

Flutter Doctor输出

Doctor输出

[√] Flutter (Channel stable, 3.22.0, on Microsoft Windows [Version 10.0.19045.4651], locale de-DE)
• Flutter version 3.22.0 on channel stable at C:\Users\escam\fvm\versions\3.22.0
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 5dcb86f68f (10 weeks ago), 2024-05-09 07:39:20 -0500
• Engine revision f6344b75dc
• Dart version 3.4.0
• DevTools version 2.34.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
• Android SDK at C:\Users\escam\AppData\Local\Android\sdk
• Platform android-34, build-tools 33.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.6.2)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.6.33723.286
• Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2022.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[√] VS Code, 64-bit edition (version 1.91.1)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 3.92.0

[√] Connected device (4 available)
• sdk gphone x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33) (emulator)
• Windows (desktop)          • windows       • windows-x64    • Microsoft Windows [Version 10.0.19045.4651]
• Chrome (web)               • chrome        • web-javascript • Google Chrome 126.0.6478.127
• Edge (web)                 • edge          • web-javascript • Microsoft Edge 126.0.2592.102

[√] Network resources
• All expected network resources are available.
kyvafyod

kyvafyod1#

@escamoteur
The stacktrace matches #97583 , so please check if the code sample given in it resembles your case or not.

tgabmvqs

tgabmvqs2#

你为什么认为堆栈跟踪是相同的?错误是不同的,这里的错误是在 widget 属性中出现了空值错误。这实际上不应该发生。它似乎与我关于 _state 为空的其他报告有关。

46scxncf

46scxncf3#

堆栈跟踪让我想起了另一个神秘的崩溃(b/274579658)。在这种情况下,看起来我们试图膨胀一个 Scrollable ,而它的 findAncestorWidgetOfExactType 实际上返回了一个未挂载的祖先。

File "framework.dart", line 5512, in ComponentElement.performRebuild
  File "framework.dart", line 5203, in Element.rebuild

这个调用路径表明 Scrollable 的父节点(以及几个祖先)仍然处于活动状态,这有点令人困惑——如果 PageStorage 祖先已卸载,那么它所有的后代都应该已卸载,除非:

  • 某种方式,一个活动的树被重新分配到了未挂载的分支上(但 _retakeInactiveElement 访问了 Element.widget ,所以似乎不可能),
  • 一个元素在其 visitChildren 实现中遗漏了一个子节点(并且该子节点在 BuildScope 的脏列表中有后代)。

因此,我认为要么是这样,要么是本应卸载子树的 Element.unmount 调用以某种方式被中断了。

p8h8hvxi

p8h8hvxi4#

你为什么认为堆栈跟踪是相同的?
我根据这个问题指向 ScrollControllerPageStorage,这两个问题与我链接的问题密切相关。
保持问题的开放状态,以便团队进行跟踪。

相关问题