The getter 'data' was called on null , Receiver: null, Tried calling

控制台报错如下:

══╡ 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): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
I/flutter (26961): #1      DetailsTopArea.build.<anonymous closure> (package:flutter_shop/pages/details_page/details_top_area.dart:17:66)
I/flutter (26961): #2      Provide.build.<anonymous closure> (package:provide/provide.dart:289:43)
I/flutter (26961): #3      ListeningBuilder.build (package:provide/provide.dart:629:12)
I/flutter (26961): #4      _AnimatedState.build (package:flutter/src/widgets/transitions.dart:148:48)
I/flutter (26961): #5      StatefulElement.build (package:flutter/src/widgets/framework.dart:3824:27)
I/flutter (26961): #6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3735:15)
I/flutter (26961): #7      Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #8      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #9      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3863:11)
I/flutter (26961): #10     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #11     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #12     Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3746:16)
I/flutter (26961): #14     Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #15     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #16     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #17     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #18     Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #19     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3746:16)
I/flutter (26961): #20     Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #21     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #22     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #23     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #24     Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #25     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4875:14)
I/flutter (26961): #26     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #27     Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #28     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4875:14)
I/flutter (26961): #29     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #30     Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #31     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3746:16)
I/flutter (26961): #32     Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #33     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #34     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #35     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #36     Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #37     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3746:16)
I/flutter (26961): #38     Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #39     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #40     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #41     ParentDataElement.mount (package:flutter/src/widgets/framework.dart:4062:11)
I/flutter (26961): #42     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #43     Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #44     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3746:16)
I/flutter (26961): #45     Element.rebuild (package:flutter/src/widgets/framework.dart:3558:5)
I/flutter (26961): #46     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3715:5)
I/flutter (26961): #47     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3863:11)
I/flutter (26961): #48     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3710:5)
I/flutter (26961): #49     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2954:14)
I/flutter (26961): #50     Element.updateChild (package:flutter/src/widgets/framework.dart:2757:12)
I/flutter (26961): #51     SliverMultiBoxAdaptorElement.updateChild (package:flutter/src/widgets/sliver.dart:1030:36)
I/flutter (26961): #52     SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1015:20)
I/flutter (26961): #53     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2251:19)
I/flutter (26961): #54     SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1008:11)
I/flutter (26961): #55     RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:275:23)
I/flutter (26961): #56     RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1740:58)
I/flutter (26961): #57     PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:797:15)
I/flutter (26961): #58     RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1740:13)
I/flutter (26961): #59     RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:264:5)
I/flutter (26961): #60     RenderSliverMultiBoxAdaptor.addInitialChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:348:5)
I/flutter (26961): #61     RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:78:12)
I/flutter (26961): #62     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #63     RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:182:11)
I/flutter (26961): #64     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #65     RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:407:13)
I/flutter (26961): #66     RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1322:12)
I/flutter (26961): #67     RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1240:20)
I/flutter (26961): #68     RenderObject.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): #70     RenderObject.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): #72     RenderObject.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): #74     RenderObject.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): #76     RenderObject.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): #78     RenderObject.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): #80     RenderObject.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): #82     RenderObject.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): #84     RenderObject.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): #86     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
I/flutter (26961): #87     MultiChildLayoutDelegate.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): #89     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
I/flutter (26961): #90     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
I/flutter (26961): #91     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1519:7)
I/flutter (26961): #92     PipelineOwner.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 = {
      'goodId': id,
    };
     request('getGoodDetailById', formData: formData).then((val) {
      var responseData = json.decode(val.toString());

      goodsInfo = DetailsModel.fromJson(responseData);
      notifyListeners();
    });
  }

使用异步处理之后的代码为(async--await):

//发送请求  使用async--await
  getGoodsInfo(String id) async {
    var formData = {
      'goodId': id,
    };
    await request('getGoodDetailById', formData: formData).then((val) {
      var responseData = json.decode(val.toString());

      goodsInfo = DetailsModel.fromJson(responseData);
      notifyListeners();
    });
  }
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,080评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,422评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,630评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,554评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,662评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,856评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,014评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,752评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,212评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,541评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,687评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,347评论 4 331
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,973评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,777评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,006评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,406评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,576评论 2 349

推荐阅读更多精彩内容