'Exception Caught by widgets library
I am getting an exception when fetching data from API and listing it using ListView
When I am giving itemCount less than the total fetched data then its working fine and showing one less element without any infinte scrolling else its showing error with infinite scrolling, here is the code:
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)));
}));
}),
)
Here is the Run error I am getting:
I/flutter (17054): url got https://www.triply.fun/tc-api/adpepv/tickets_info/20/1/
I/flutter (17054): Data fetched [Instance of 'TicketsInfo', Instance of 'TicketsInfo', Instance of 'TicketsInfo', Instance of 'TicketsInfo', Instance of 'TicketsInfo', Instance of 'TicketsInfo', Instance of 'TicketsInfo', Instance of 'TicketsInfo', Instance of 'TicketsInfo', Instance of 'TicketsInfo', Instance of 'TicketsInfo']
I/flutter (17054): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (17054): The following NoSuchMethodError was thrown building:
I/flutter (17054): The getter 'buyerFirst' was called on null.
I/flutter (17054): Receiver: null
I/flutter (17054): Tried calling: buyerFirst
I/flutter (17054):
I/flutter (17054): When the exception was thrown, this was the stack:
I/flutter (17054): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
I/flutter (17054): #1 _ListScreenState.build.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:check_in/src/screens/list_screen.dart:141:94)
I/flutter (17054): #2 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:397:15)
I/flutter (17054): #3 SliverMultiBoxAdaptorElement._build.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1000:67)
I/flutter (17054): #4 _HashMap.putIfAbsent (dart:collection/runtime/libcollection_patch.dart:143:29)
I/flutter (17054): #5 SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1000:26)
I/flutter (17054): #6 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package: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 RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:274:23)
I/flutter (17054): #10 RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1730:58)
I/flutter (17054): #11 PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:799:15)
I/flutter (17054): #12 RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1730:13)
I/flutter (17054): #13 RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:263:5)
I/flutter (17054): #14 RenderSliverMultiBoxAdaptor.insertAndLayoutChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:401:5)
I/flutter (17054): #15 RenderSliverList.performLayout.advance (package:flutter/src/rendering/sliver_list.dart:190:19)
I/flutter (17054): #16 RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:233:19)
I/flutter (17054): #17 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (17054): #18 RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:182:11)
I/flutter (17054): #19 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (17054): #20 RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:405:13)
I/flutter (17054): #21 RenderShrinkWrappingViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1645:12)
I/flutter (17054): #22 RenderShrinkWrappingViewport.performLayout (package:flutter/src/rendering/viewport.dart:1608:20)
I/flutter (17054): #23 RenderObject.layout (package: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 (package: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 (package: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 (package: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 (package: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 (package: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 (package: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 (package: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 (package: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 (package:flutter/src/rendering/object.dart:1509:7)
I/flutter (17054): #42 PipelineOwner.flushLayout (package: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 (package:flutter/src/rendering/binding.dart:219:5)
I/flutter (17054): #46 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package: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 (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (17054): #49 _invoke (dart:ui/hooks.dart:154:13)
I/flutter (17054): #50 _drawFrame (dart:ui/hooks.dart:143:3)
I/flutter (17054): ════════════════════════════════════════════════════════════════════════════════════════════════════
Solution 1:[1]
You can remove data before buyerFirst
and try it again:
${snapshot.data[index]**.data**.buyerFirst}
${snapshot.data[index].data.buyerFirst}
replace with:
${snapshot.data[index].buyerFirst} ${snapshot.data[index].buyerFirst}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ×¡×˜× ×œ×™ ×’×¨×•× ×Ÿ |