小部件库捕获的异常

时间:2019-01-19 20:21:33

标签: dart flutter

从api获取数据并使用ListView列出数据时出现异常

当我给itemCount少于获取的总数据时,它的运行状况很好,并且显示了一个更少的元素而没有无限滚动,否则由于无限滚动而显示错误,这是代码:

Expanded(
              child: StreamBuilder(
                initialData: 'https://www.triply.fun/tc-api/adpepv/tickets_info/20/1/',
                  stream: apiURL,
                  builder: (context, snapshotVal) {
                    return Container(
                        child: FutureBuilder<List<TicketsInfo>>(
                            future: ticketInfo(snapshotVal.data),
                            builder: (context, snapshot) {
                              return (snapshot.hasData &&
                                      snapshot.data.length != null && snapshot.data.length > 0 )
                                  ? ListView.builder(
                                      scrollDirection: Axis.vertical,
                                      shrinkWrap: true,
                                      padding: EdgeInsets.only(bottom: 20),
                                      itemBuilder: (context, int index) {
                                        return GestureDetector(
                                          onTap: () => Navigator.pushNamed(
                                              context, "/Detail"),
                                          child: Column(
                                            children: <Widget>[
                                              Container(
                                                height: 1,
                                                color: Colors.black12,
                                              ),
                                              Container(
                                                  padding:
                                                      EdgeInsets.all(0),
                                                  margin: EdgeInsets.all(0),
                                                  child: Row(
                                                    children: <Widget>[
                                                      Expanded(
                                                        child: Container(
                                                          padding: EdgeInsets
                                                              .symmetric(
                                                                  horizontal:
                                                                      20),
                                                          alignment: Alignment
                                                              .centerLeft,
                                                          child: Text(
                                                            "${snapshot.data[index].data.buyerFirst} ${snapshot.data[index].data.buyerFirst}",
                                                            style: textStyle(
                                                                kColor_dark_text,
                                                                FontWeight
                                                                    .w400,
                                                                16),
                                                          ),
                                                          height: 74,
                                                        ),
                                                      ),
                                                      Container(
                                                        width: 40,
                                                        child: Image.asset(
                                                          ic_forward,
                                                          fit: BoxFit
                                                              .contain,
                                                          height: 10,
                                                          width: 6,
                                                        ),
                                                      ),
                                                      Padding(
                                                          padding: EdgeInsets
                                                              .only(
                                                                  left: 10))
                                                    ],
                                                  )),
                                            ],
                                          ),
                                        );
                                      },
                                      itemCount: snapshot.data.length)
                                  : Center(
                                      child: CircularProgressIndicator(
                                          valueColor:
                                              AlwaysStoppedAnimation<Color>(
                                                  kColor_green_theme)));
                            }));
                  }),
            )

这是我遇到的运行错误:

  

I / flutter(17054):网址为https://www.triply.fun/tc-api/adpepv/tickets_info/20/1/   I / flutter(17054):已获取数据[TicketsInfo的实例,TicketsInfo的实例,TicketsInfo的实例,TicketsInfo的实例,TicketsInfo的实例,TicketsInfo的实例,TicketsInfo的实例','TicketsInfo'的实例,'TicketsInfo'的实例,'TicketsInfo'的实例,'TicketsInfo'的实例]   I / flutter(17054):W小工具库引起的异常CA ═════════════════════════   I / flutter(17054):构建时引发了以下NoSuchMethodError:   I / flutter(17054):将getter'buyerFirst'调用为null。   I / flutter(17054):接收者:null   I / flutter(17054):尝试致电:buyerFirst   I /颤振(17054):   I / flutter(17054):引发异常时,这是堆栈:   I / Flutter(17054):#0 Object.noSuchMethod(dart:core / runtime / libobject_patch.dart:50:5)   I / flutter(17054):#1 _ListScreenState.build ...(软件包:check_in / src / screens / list_screen.dart:141:94)   I / flutter(17054):#2 SliverChildBuilderDelegate.build(包:flutter / src / widgets / sliver.dart:397:15)   I / flutter(17054):#3 SliverMultiBoxAdaptorElement._build。 (软件包:flutter / src / widgets / sliver.dart:1000:67)   我/颤振(17054):#4 _HashMap.putIfAbsent(dart:collection / runtime / libcollection_patch.dart:143:29)   I / flutter(17054):#5 SliverMultiBoxAdaptorElement._build(包:flutter / src / widgets / sliver.dart:1000:26)   I / flutter(17054):#6 SliverMultiBoxAdaptorElement.createChild。 (软件包:flutter / src / widgets / sliver.dart:1013:55)   I / flutter(17054):#7 BuildOwner.buildScope(package:flutter / src / widgets / framework.dart:2266:19)   I / flutter(17054):#8 SliverMultiBoxAdaptorElement.createChild(package:flutter / src / widgets / sliver.dart:1006:11)   I / flutter(17054):#9 RenderSliv​​erMultiBoxAdaptor._createOrObtainChild。 (package:flutter / src / rendering / sliver_multi_box_adaptor.dart:274:23)   I / flutter(17054):#10 RenderObject.invokeLayoutCallback。 (包:flutter / src / rendering / object.dart:1730:58)   I / flutter(17054):#11 PipelineOwner._enableMutationsToDirtySubtrees(包:flutter / src / rendering / object.dart:799:15)   I / flutter(17054):#12 RenderObject.invokeLayoutCallback(软件包:flutter / src / rendering / object.dart:1730:13)   I / flutter(17054):#13 RenderSliv​​erMultiBoxAdaptor._createOrObtainChild(包:flutter / src / rendering / sliver_multi_box_adaptor.dart:263:5)   I / flutter(17054):#14 RenderSliv​​erMultiBoxAdaptor.insertAndLayoutChild(包:flutter / src / rendering / sliver_multi_box_adaptor.dart:401:5)   I / flutter(17054):#15 RenderSliv​​erList.performLayout.advance(包:flutter / src / rendering / sliver_list.dart:190:19)   I / flutter(17054):#16 RenderSliv​​erList.performLayout(包:flutter / src / rendering / sliver_list.dart:233:19)   I / flutter(17054):#17 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)   I / flutter(17054):#18 RenderSliv​​erPadding.performLayout(包:flutter / src / rendering / sliver_padding.dart:182:11​​)   I / flutter(17054):#19 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)   I / flutter(17054):#20 RenderViewportBase.layoutChildSequence(软件包:flutter / src / rendering / viewport.dart:405:13)   I / flutter(17054):#21 RenderShrinkWrappingViewport._attemptLayout(包:flutter / src / rendering / viewport.dart:1645:12)   I / flutter(17054):#22 RenderShrinkWrappingViewport.performLayout(包:flutter / src / rendering / viewport.dart:1608:20)   I / flutter(17054):#23 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)   I / flutter(17054):#24 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)   I / flutter(17054):#25 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)   I / flutter(17054):#26 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)   I / flutter(17054):#27 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)   I / flutter(17054):#28 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)   I / flutter(17054):#29 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)   I / flutter(17054):#30 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)   I / flutter(17054):#31 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)   I / flutter(17054):#32 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)   I / flutter(17054):#33 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)   I / flutter(17054):#34 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)   I / flutter(17054):#35 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)   I / flutter(17054):#36 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)   I / flutter(17054):#37 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)   I / flutter(17054):#38 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)   I / flutter(17054):#39 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)   I / flutter(17054):#40 RenderFlex.performLayout(package:flutter / src / rendering / flex.dart:798:17)   I / flutter(17054):#41 RenderObject._layoutWithoutResize(软件包:flutter / src / rendering / object.dart:1509:7)   I / flutter(17054):#42 PipelineOwner.flushLayout(软件包:flutter / src / rendering / object.dart:768:18)   I / flutter(17054):#43 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame(package:flutter / src / rendering / binding.dart:281:19)   I / flutter(17054):#44 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame(package:flutter / src / widgets / binding.dart:677:13)   I / flutter(17054):#45 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback(包:flutter / src / rendering / binding.dart:219:5)   I / flutter(17054):#46 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback(软件包:flutter / src / scheduler / binding.dart:990:15)   I / flutter(17054):#47 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame(package:flutter / src / scheduler / binding.dart:930:9)   I / flutter(17054):#48 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame(包:flutter / src / scheduler / binding.dart:842:5)   I / flutter(17054):#49 _invoke(dart:ui / hooks.dart:154:13)   I /颤振(17054):#50 _drawFrame(dart:ui / hooks.dart:143:3)   I /颤振(17054):═══════════════════════════════════════════ ══════════════════════════════════════════════════ ═══════

1 个答案:

答案 0 :(得分:0)

您可以删除buyerFirst之前的数据,然后重试:

${snapshot.data[index]**.data**.buyerFirst}
${snapshot.data[index].data.buyerFirst}

替换为:

${snapshot.data[index].buyerFirst} ${snapshot.data[index].buyerFirst}