控制台报错如下:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (26961): The following NoSuchMethodError was thrown building ListeningBuilder(animation: Instance of
I/flutter (26961): 'DetailsInfoProvide', dirty, dependencies: [_InheritedProviders], state: _AnimatedState#34350):
I/flutter (26961): The getter 'data' was called on null.
I/flutter (26961): Receiver: null
I/flutter (26961): Tried calling: data
I/flutter (26961):
I/flutter (26961): When the exception was thrown, this was the stack:
I/flutter (26961): #0Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
I/flutter (26961): #1DetailsTopArea.build. (package:flutter_shop/pages/details_page/details_top_area.dart:17:66)
I/flutter (26961): #2Provide.build. (package:provide/provide.dart:289:43)
I/flutter (26961): #3ListeningBuilder.build (package:provide/provide.dart:629:12)
I/flutter (26961): #4_AnimatedState.build (package:flutter/src/widgets/transitions.dart:148:48)
I/flutter (26961): #5StatefulElement.build (package:flutter/src/widgets/framework.dart:3824:27)
I/flutter (26961): #6ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3735:15)
I/flutter (26961): #7Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #8ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #9StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3863:11)
I/flutter (26961): #10ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #11Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #12Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #13ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3746:16)
I/flutter (26961): #14Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #15ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #16ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #17Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #18Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #19ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3746:16)
I/flutter (26961): #20Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #21ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #22ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #23Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #24Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #25SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4875:14)
I/flutter (26961): #26Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #27Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #28SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4875:14)
I/flutter (26961): #29Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #30Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #31ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3746:16)
I/flutter (26961): #32Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #33ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #34ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #35Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #36Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #37ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3746:16)
I/flutter (26961): #38Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #39ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #40ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #41ParentDataElement.mount (package:flutter/src/widgets/framework.dart:4062:11)
I/flutter (26961): #42Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #43Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #44ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3746:16)
I/flutter (26961): #45Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #46ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #47StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3863:11)
I/flutter (26961): #48ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #49Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #50Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #51SliverMultiBoxAdaptorElement.updateChild (package:flutter/src/widgets/sliver.dart:1030:36)
I/flutter (26961): #52SliverMultiBoxAdaptorElement.createChild. (package:flutter/src/widgets/sliver.dart:1015:20)
I/flutter (26961): #53BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2251:19)
I/flutter (26961): #54SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1008:11)
I/flutter (26961): #55RenderSliverMultiBoxAdaptor._createOrObtainChild. (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:275:23)
I/flutter (26961): #56RenderObject.invokeLayoutCallback. (package:flutter/src/rendering/object.dart:1740:58)
I/flutter (26961): #57PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:797:15)
I/flutter (26961): #58RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1740:13)
I/flutter (26961): #59RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:264:5)
I/flutter (26961): #60RenderSliverMultiBoxAdaptor.addInitialChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:348:5)
I/flutter (26961): #61RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:78:12)
I/flutter (26961): #62RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #63RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:182:11)
I/flutter (26961): #64RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #65RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:407:13)
I/flutter (26961): #66RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1322:12)
I/flutter (26961): #67RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1240:20)
I/flutter (26961): #68RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #69_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26961): #70RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #71_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26961): #72RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #73_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26961): #74RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #75_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26961): #76RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #77_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26961): #78RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #79_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26961): #80RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #81_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26961): #82RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #83_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26961): #84RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #85_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26961): #86RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #87MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
I/flutter (26961): #88_ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:431:7)
I/flutter (26961): #89MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
I/flutter (26961): #90RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
I/flutter (26961): #91RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1519:7)
I/flutter (26961): #92PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:766:18)
I/flutter (26961): #93_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:336:19)
I/flutter (26961): #94_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:701:13)
I/flutter (26961): #95_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:275:5)
I/flutter (26961): #96_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15)
I/flutter (26961): #97_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:952:9)
I/flutter (26961): #98_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:864:5)
I/flutter (26961): #102_invoke (dart:ui/hooks.dart:219:10)
I/flutter (26961): #103_drawFrame (dart:ui/hooks.dart:178:3)
I/flutter (26961): (elided 3 frames from package dart:async)
我这里的原因是由于
DetailsInfoProvide
这个provide
中的请求不是异步,造成了初始时data
数据为空,从而导致了控制台异常抛出,而ui界面会先出现瞬间的崩溃然后变为正常。没有使用异步处理之前的代码:
//发送请求
getGoodsInfo(String id){
var formData = https://www.it610.com/article/{'goodId': id,
};
request('getGoodDetailById', formData: formData).then((val) {
var responseData = https://www.it610.com/article/json.decode(val.toString());
goodsInfo = DetailsModel.fromJson(responseData);
notifyListeners();
});
}
【The|The getter 'data' was called on null , Receiver: null, Tried calling】使用异步处理之后的代码为(
async--await
)://发送请求使用async--await
getGoodsInfo(String id) async {
var formData = https://www.it610.com/article/{'goodId': id,
};
await request('getGoodDetailById', formData: formData).then((val) {
var responseData = https://www.it610.com/article/json.decode(val.toString());
goodsInfo = DetailsModel.fromJson(responseData);
notifyListeners();
});
}