Исключение Flutter ‘пакет: flutter / src/widgets/sliver.dart’: неудачное утверждение ‘дочерний элемент!= null’ неверно

#dart #flutter

#dart #flutter

Вопрос:

Я получаю это исключение из пакета flutter sliver.dart, когда я перехожу на новую страницу.

Все это работало нормально, но позже я попытался добавить к нему несколько функций, таких как подключение базы данных sqlite, я подумал, что это будет проблемой, поэтому я попытался вернуться к последнему рабочему состоянию моего приложения, удалив каждый дополнительный код. Но, к сожалению, это все еще выдает мне эту ошибку. Даже если вы посмотрите на мой приведенный ниже код интерфейса, сейчас там нет ничего особенного, это просто отображение данных, которые у меня уже есть в объекте.

Пробовал полностью переустановить приложение, но решения по-прежнему нет.

 Running "flutter packages get" in heron...                          1.5s
Launching libmain.dart on Android SDK built for x86 in debug mode...
Built buildappoutputsapkdebugapp-debug.apk.
D/        (23206): HostConnection::get() New Host Connection established 0xa4b249c0, tid 23228
D/EGL_emulation(23206): eglMakeCurrent: 0xa6594cc0: ver 3 0 (tinfo 0x94a360d0)
I/flutter (23206): TV GET Requested
I/flutter (23206): Movie GET Requested
I/flutter (23206): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (23206): The following assertion was thrown during performLayout():
I/flutter (23206): 'package:flutter/src/widgets/sliver.dart': Failed assertion: line 553 pos 12: 'child != null': is
I/flutter (23206): not true.
I/flutter (23206): 
I/flutter (23206): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (23206): more information in this error message to help you determine and fix the underlying cause.
I/flutter (23206): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (23206):   https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (23206): 
I/flutter (23206): When the exception was thrown, this was the stack:
I/flutter (23206): #2      SliverChildListDelegate.build 
I/flutter (23206): #3      SliverMultiBoxAdaptorElement._build.<anonymous closure> 
I/flutter (23206): #4      _HashMap.putIfAbsent (dart:collection/runtime/libcollection_patch.dart:137:29)
I/flutter (23206): #5      SliverMultiBoxAdaptorElement._build 
I/flutter (23206): #6      SliverMultiBoxAdaptorElement.createChild.<anonymous closure> 
I/flutter (23206): #7      BuildOwner.buildScope 
I/flutter (23206): #8      SliverMultiBoxAdaptorElement.createChild 
I/flutter (23206): #9      RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> 
I/flutter (23206): #10     RenderObject.invokeLayoutCallback.<anonymous closure> 
I/flutter (23206): #11     PipelineOwner._enableMutationsToDirtySubtrees 
I/flutter (23206): #12     RenderObject.invokeLayoutCallback 
I/flutter (23206): #13     RenderSliverMultiBoxAdaptor._createOrObtainChild 
I/flutter (23206): #14     RenderSliverMultiBoxAdaptor.insertAndLayoutChild 
I/flutter (23206): #15     RenderSliverList.performLayout.advance 
I/flutter (23206): #16     RenderSliverList.performLayout 
I/flutter (23206): #17     RenderObject.layout 
I/flutter (23206): #18     RenderSliverPadding.performLayout 
I/flutter (23206): #19     RenderObject.layout 
I/flutter (23206): #20     RenderViewportBase.layoutChildSequence 
I/flutter (23206): #21     RenderViewport._attemptLayout 
I/flutter (23206): #22     RenderViewport.performLayout 
I/flutter (23206): #23     RenderObject.layout 
I/flutter (23206): #24     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #25     RenderObject.layout 
I/flutter (23206): #26     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #27     RenderObject.layout 
I/flutter (23206): #28     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #29     RenderObject.layout 
I/flutter (23206): #30     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #31     RenderObject.layout 
I/flutter (23206): #32     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #33     RenderObject.layout 
I/flutter (23206): #34     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #35     RenderObject.layout 
I/flutter (23206): #36     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #37     RenderObject.layout 
I/flutter (23206): #38     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #39     RenderObject.layout 
I/flutter (23206): #40     RenderPadding.performLayout 
I/flutter (23206): #41     RenderObject.layout 
I/flutter (23206): #42     MultiChildLayoutDelegate.layoutChild 
I/flutter (23206): #43     _ScaffoldLayout.performLayout 
I/flutter (23206): #44     MultiChildLayoutDelegate._callPerformLayout 
I/flutter (23206): #45     RenderCustomMultiChildLayoutBox.performLayout 
I/flutter (23206): #46     RenderObject.layout 
I/flutter (23206): #47     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #48     RenderObject.layout 
I/flutter (23206): #49     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #50     _RenderCustomClip.performLayout 
I/flutter (23206): #51     RenderObject.layout 
I/flutter (23206): #52     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #53     RenderObject.layout 
I/flutter (23206): #54     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #55     RenderObject.layout 
I/flutter (23206): #56     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #57     RenderObject.layout 
I/flutter (23206): #58     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #59     RenderObject.layout 
I/flutter (23206): #60     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #61     RenderObject.layout 
I/flutter (23206): #62     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #63     RenderObject.layout 
I/flutter (23206): #64     _RenderProxyBoxamp;RenderBoxamp;RenderObjectWithChildMixinamp;RenderProxyBoxMixin.performLayout 
I/flutter (23206): #65     RenderObject.layout 
I/flutter (23206): #66     RenderOffstage.performLayout 
I/flutter (23206): #67     RenderObject.layout 
I/flutter (23206): #68     RenderStack.performLayout 
I/flutter (23206): #69     RenderObject._layoutWithoutResize 
I/flutter (23206): #70     PipelineOwner.flushLayout 
I/flutter (23206): #71     _WidgetsFlutterBindingamp;BindingBaseamp;GestureBindingamp;ServicesBindingamp;SchedulerBindingamp;PaintingBindingamp;SemanticsBindingamp;RendererBinding.drawFrame 
I/flutter (23206): #72     _WidgetsFlutterBindingamp;BindingBaseamp;GestureBindingamp;ServicesBindingamp;SchedulerBindingamp;PaintingBindingamp;SemanticsBindingamp;RendererBindingamp;WidgetsBinding.drawFrame 
I/flutter (23206): #73     _WidgetsFlutterBindingamp;BindingBaseamp;GestureBindingamp;ServicesBindingamp;SchedulerBindingamp;PaintingBindingamp;SemanticsBindingamp;RendererBinding._handlePersistentFrameCallback 
I/flutter (23206): #74     _WidgetsFlutterBindingamp;BindingBaseamp;GestureBindingamp;ServicesBindingamp;SchedulerBinding._invokeFrameCallback 
I/flutter (23206): #75     _WidgetsFlutterBindingamp;BindingBaseamp;GestureBindingamp;ServicesBindingamp;SchedulerBinding.handleDrawFrame 
I/flutter (23206): #76     _WidgetsFlutterBindingamp;BindingBaseamp;GestureBindingamp;ServicesBindingamp;SchedulerBinding._handleDrawFrame 
I/flutter (23206): #80     _invoke (dart:ui/hooks.dart:209:10)
I/flutter (23206): #81     _drawFrame (dart:ui/hooks.dart:168:3)
I/flutter (23206): (elided 5 frames from class _AssertionError and package dart:async)
I/flutter (23206): 
I/flutter (23206): The following RenderObject was being processed when the exception was fired:
I/flutter (23206):   RenderSliverList#19980 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (23206):   creator: SliverListMediaQuerySliverPaddingViewportIgnorePointer-[GlobalKey#7290e] ←
I/flutter (23206):   SemanticsListener_GestureSemanticsI/flutter (23206):   RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#9ea0f] ← _ScrollableScopeI/flutter (23206):   _ScrollSemantics-[GlobalKey#aa43f] ← RepaintBoundary ← ⋯
I/flutter (23206):   parentData: paintOffset=Offset(0.0, 0.0) (can use size)
I/flutter (23206):   constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward, ScrollDirection.idle,
I/flutter (23206):   scrollOffset: 0.0, remainingPaintExtent: 598.4, crossAxisExtent: 381.4, crossAxisDirection:
I/flutter (23206):   AxisDirection.right, viewportMainAxisExtent: 598.4, remainingCacheExtent: 848.4 cacheOrigin: 0.0 )
I/flutter (23206):   geometry: null
I/flutter (23206):   currently live children: 0 to 2
I/flutter (23206): This RenderObject had the following descendants (showing up to depth 5):
I/flutter (23206):   RenderIndexedSemantics#6d89b relayoutBoundary=up3 NEEDS-PAINT
I/flutter (23206):     RenderRepaintBoundary#41a15 relayoutBoundary=up4 NEEDS-PAINT
I/flutter (23206):       RenderConstrainedBox#f6331 relayoutBoundary=up5 NEEDS-PAINT
I/flutter (23206):         RenderStack#1d492 NEEDS-PAINT
I/flutter (23206):           RenderSemanticsAnnotations#dee5b relayoutBoundary=up1 NEEDS-PAINT
I/flutter (23206):           RenderSemanticsAnnotations#75402 NEEDS-PAINT
I/flutter (23206):           RenderConstrainedBox#553a7 relayoutBoundary=up1 NEEDS-PAINT
I/flutter (23206):   RenderIndexedSemantics#dbd86 relayoutBoundary=up3 NEEDS-PAINT
I/flutter (23206):     RenderRepaintBoundary#d9292 relayoutBoundary=up4 NEEDS-PAINT
I/flutter (23206):       RenderDecoratedBox#fdc4c relayoutBoundary=up5 NEEDS-PAINT
I/flutter (23206):         RenderSemanticsGestureHandler#fac22 relayoutBoundary=up6 NEEDS-PAINT
I/flutter (23206):           RenderPointerListener#bca58 relayoutBoundary=up7 NEEDS-PAINT
I/flutter (23206):   RenderIndexedSemantics#dc7c8 relayoutBoundary=up3 NEEDS-PAINT
I/flutter (23206):     RenderRepaintBoundary#f0361 relayoutBoundary=up4 NEEDS-PAINT
I/flutter (23206):       RenderSemanticsGestureHandler#29897 relayoutBoundary=up5 NEEDS-PAINT
I/flutter (23206):         RenderPointerListener#e3417 relayoutBoundary=up6 NEEDS-PAINT
I/flutter (23206):           RenderSemanticsAnnotations#69a6f relayoutBoundary=up7 NEEDS-PAINT
I/flutter (23206): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (23206): Another exception was thrown: NoSuchMethodError: The getter 'scrollOffsetCorrection' was called on null.
I/flutter (23206): Another exception was thrown: NoSuchMethodError: The method 'debugAssertIsValid' was called on null.
I/flutter (23206): Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.

  

Я разделил свой код на две страницы

интерфейс — https://gist.github.com/purplecandy/54234b2080f27b43075ef289489ecf5b

функции — https://gist.github.com/purplecandy/8d7a8cb0e3e001d6517ddc21dde72256

pubspec — https://gist.github.com/purplecandy/06be5d9a521239052a25cbe6e042471b

Кто-нибудь может дать мне некоторое представление о том, что вызывает эту проблему? Где я ошибаюсь? Или просто объясните мне ошибку

Комментарии:

1. @Vega это означает, что у виджета должен был быть ненулевой дочерний элемент.

2. @CopsOnRoad Итак, один из виджетов возвращает null. Я разберусь с этим

3. @NadeemSiddique это означает, что вы пропустили или не предоставили child виджету

4. @CopsOnRoad спасибо, приятель, нашел решение. Проблема заключалась в том, что я пытался связать один и тот же виджет со всеми переменными вместе, например: Widget foo,bar = CircularProgressIndicator(); Я думал, что это должно сработать, но это не сработало, пришлось писать отдельно. Хотелось бы знать, почему это не сработало таким образом? Переменные могут быть назначены таким образом, верно

5. Вы объявили foo и инициализировали bar , извините, я этого не понял.

Ответ №1:

Исходя из журналов, ожидаемое child значение виджета, похоже, равно нулю. Если у вас все еще возникают проблемы, совместное использование фрагментов кода строки, вызывающей ошибку, должно помочь нам разобраться в проблеме.