我正在构建我的第一个Flutter应用程序,但遇到了我无法解决的问题。

该应用程序从Firebase实时数据库检索数据,将所有条目添加到列表中,并在PageView的第一页中显示所有条目。

当我以 Debug模式启动应用程序时,出现以下错误:

I/flutter ( 7901): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 7901): The following NoSuchMethodError was thrown during performLayout():
I/flutter ( 7901): The getter 'key' was called on null.
I/flutter ( 7901): Receiver: null
I/flutter ( 7901): Tried calling: key
I/flutter ( 7901): User-created ancestor of the error-causing widget was:
I/flutter ( 7901):   PageView-[#62d48] file:///home/amedeo/AndroidStudioProjects/pastore_app/lib/main.dart:241:17
I/flutter ( 7901): When the exception was thrown, this was the stack:
I/flutter ( 7901): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
I/flutter ( 7901): #1      SliverChildListDelegate.build (package:flutter/src/widgets/sliver.dart:672:27)
I/flutter ( 7901): #2      SliverMultiBoxAdaptorElement._build.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1153:67)
I/flutter ( 7901): #3      _HashMap.putIfAbsent (dart:collection-patch/collection_patch.dart:137:29)
I/flutter ( 7901): #4      SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1153:26)
I/flutter ( 7901): #5      SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1166:55)
I/flutter ( 7901): #6      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2328:19)
I/flutter ( 7901): #7      SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1159:11)
I/flutter ( 7901): #8      RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:354:23)
I/flutter ( 7901): #9      RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1797:58)
I/flutter ( 7901): #10     PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:875:15)
I/flutter ( 7901): #11     RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1797:13)
I/flutter ( 7901): #12     RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:343:5)
I/flutter ( 7901): #13     RenderSliverMultiBoxAdaptor.addInitialChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:427:5)
I/flutter ( 7901): #14     RenderSliverFixedExtentBoxAdaptor.performLayout (package:flutter/src/rendering/sliver_fixed_extent_list.dart:196:12)
I/flutter ( 7901): #15     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #16     RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:406:13)
I/flutter ( 7901): #17     RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1352:12)
I/flutter ( 7901): #18     RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1270:20)
I/flutter ( 7901): #19     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #20     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #21     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #22     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #23     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #24     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #25     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #26     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #27     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #28     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #29     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #30     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #31     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #32     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #33     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #34     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #35     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #36     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #37     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #38     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
I/flutter ( 7901): #39     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:444:7)
I/flutter ( 7901): #40     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
I/flutter ( 7901): #41     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
I/flutter ( 7901): #42     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #43     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #44     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #45     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #46     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1232:11)
I/flutter ( 7901): #47     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #48     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #49     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #50     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #51     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #52     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #53     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #54     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #55     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #56     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #57     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #58     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #59     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #60     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #61     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #62     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #63     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3140:13)
I/flutter ( 7901): #64     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #65     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter ( 7901): #66     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #67     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #68     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #69     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #70     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #71     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #72     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #73     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #74     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #75     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 7901): #76     RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 7901): #77     RenderView.performLayout (package:flutter/src/rendering/view.dart:152:13)
I/flutter ( 7901): #78     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1578:7)
I/flutter ( 7901): #79     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:844:18)
I/flutter ( 7901): #80     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:341:19)
I/flutter ( 7901): #81     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:761:13)
I/flutter ( 7901): #82     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:280:5)
I/flutter ( 7901): #83     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1033:15)
I/flutter ( 7901): #84     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:975:9)
I/flutter ( 7901): #85     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:784:7)
I/flutter ( 7901): #94     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
I/flutter ( 7901): #95     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
I/flutter ( 7901): #96     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
I/flutter ( 7901): (elided 8 frames from package dart:async and package dart:async-patch)
I/flutter ( 7901): The following RenderObject was being processed when the exception was fired: RenderSliverFillViewport#d6420 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT:
I/flutter ( 7901):   creator: SliverFillViewport ← Viewport ← IgnorePointer-[GlobalKey#cec9a] ← Semantics ←
I/flutter ( 7901):     _PointerListener ← Listener ← _GestureSemantics ←
I/flutter ( 7901):     RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#9d04a] ← _PointerListener ← Listener
I/flutter ( 7901):     ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#04774] ← ⋯
I/flutter ( 7901):   parentData: paintOffset=Offset(0.0, 0.0) (can use size)
I/flutter ( 7901):   constraints: SliverConstraints(AxisDirection.right, GrowthDirection.forward, ScrollDirection.idle,
I/flutter ( 7901):     scrollOffset: 0.0, remainingPaintExtent: 600.9, crossAxisExtent: 802.7, crossAxisDirection:
I/flutter ( 7901):     AxisDirection.down, viewportMainAxisExtent: 600.9, remainingCacheExtent: 600.9 cacheOrigin: 0.0 )
I/flutter ( 7901):   geometry: null
I/flutter ( 7901):   no children current live
I/flutter ( 7901): This RenderObject has no descendants.
I/flutter ( 7901): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 7901): Another exception was thrown: NoSuchMethodError: The method 'debugAssertIsValid' was called on null.
I/flutter ( 7901): Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.

我试图将GlobalKey添加到PageView键值中,但是没有用。

也许问题出在_onEntryChanged函数中,但我对此进行了评论,问题仍然存在。
这里的代码片段:
 _onEntryChanged(Event event) {
    var oldEntry = carList.singleWhere((entry) {
      return entry.key == event.snapshot.key;
    });
    setState(() {
      carList[carList.indexOf(oldEntry)] = Car.fromSnapshot(event.snapshot);
    });
  }

这是github存储库中所有文件的链接。 GitHub Repository

如果可以帮助我,非常感谢。

最佳答案

请提供您认为会引发此错误的代码段

关于flutter - 在performLayout()期间引发了PageView NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58113410/

10-10 18:02