Another exception was thrown: FormatException: Invalid character (at character 6) - dart

I am using flutter_advanced_networkimage library to load images from server using header. But it is resulting me an exception. Here is my code:
Image(
image: AdvancedNetworkImage(
'${widget.imageURL}',
header: {
"Authorization": this.authCode,
},
useDiskCache: true,
),
fit: BoxFit.cover,
),
Error is:
flutter: This is image URL https://WEBSITEURL.ch/static/activities/picmee/1_01032019203603_0.png
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following FormatException was thrown building PicMeeTile(dirty, state: _PicMeeTileState#0993e):
flutter: Invalid character (at character 6)
flutter: https://WEBSITEURL.ch/static/activities/picmee/1_01032019203603_0.png
flutter: ^
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 _Base64Decoder.decodeChunk (dart:convert/base64.dart:675:7)
flutter: #1 _Base64Decoder.decode (dart:convert/base64.dart:600:14)
flutter: #2 Base64Decoder.convert (dart:convert/base64.dart:480:26)
flutter: #3 Base64Codec.decode (dart:convert/base64.dart:77:47)
flutter: #4 _PicMeeTileState.build (package:app/screens/picmee/list/picmeetile.dart:87:27)
flutter: #5 StatefulElement.build (package:flutter/src/widgets/framework.dart:3809:27)
flutter: #6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3721:15)
flutter: #7 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #8 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #9 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
flutter: #10 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #13 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #14 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #15 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #16 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #18 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #19 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #20 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #21 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #22 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #24 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #25 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #26 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #27 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #28 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #29 ParentDataElement.mount (package:flutter/src/widgets/framework.dart:4047:11)
flutter: #30 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #31 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #32 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #33 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #34 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #35 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
flutter: #36 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #37 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #38 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #39 SliverMultiBoxAdaptorElement.updateChild (package:flutter/src/widgets/sliver.dart:1030:36)
flutter: #40 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1015:20)
flutter: #41 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2266:19)
flutter: #42 SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1008:11)
flutter: #43 RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:274:23)
flutter: #44 RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1730:58)
flutter: #45 PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:799:15)
flutter: #46 RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1730:13)
flutter: #47 RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:263:5)
flutter: #48 RenderSliverMultiBoxAdaptor.addInitialChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:347:5)
flutter: #49 RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:78:12)
flutter: #50 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #51 RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:182:11)
flutter: #52 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #53 RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:405:13)
flutter: #54 RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1316:12)
flutter: #55 RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1234:20)
flutter: #56 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #57 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #58 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #59 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #60 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #61 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #62 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #63 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #64 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #65 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #66 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #67 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
flutter: #68 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:339:7)
flutter: #69 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
flutter: #70 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
flutter: #71 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #72 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #73 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #74 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #75 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1203:11)
flutter: #76 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #77 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
flutter: #78 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:339:7)
flutter: #79 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
flutter: #80 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
flutter: #81 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1509:7)
flutter: #82 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:768:18)
flutter: #83 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:281:19)
flutter: #84 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:686:13)
flutter: #85 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
flutter: #86 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
flutter: #87 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
flutter: #88 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
flutter: #89 _invoke (dart:ui/hooks.dart:159:13)
flutter: #90 _drawFrame (dart:ui/hooks.dart:148:3)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: This is image URL https://WEBSITEURL.ch/static/activities/picmee/1_01032019203603_0.png
flutter: Another exception was thrown: FormatException: Invalid character (at character 6)

The stack trace seems unrelated to the code shown. It appears to be from picmeetile.dart line 87, where there's a base 64 decode. Apparently the string being decoded isn't valid base 64.

Related

The getter 'length' was called on null

I trying to retrieve my data from API server and present it in my mobile application using flutter .. but i got error
The getter 'length' was called on null
Any advice plz ... thanks
my code is
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:core';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:json/add.dart';
void main() => runApp(MyApp());
Future<List> getData() async {
String url = 'http://192.168.0.55:4000/api/contacts';
http.Response response = await http.get(url);
return json.decode(response.body);
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
return MaterialApp(
routes: <String, WidgetBuilder>{
'/Add': (BuildContext context) => new Add(),
},
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
#override
HomePageState createState() {
return new HomePageState();
}
}
class HomePageState extends State<HomePage> {
List data;
void getList() async {
this.data = (await getData());
print(data);
}
#override
void initState() {
getList();
}
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
centerTitle: true,
title: new Text("Chat"),
),
body: new Center(
child: new ListView.builder(
itemCount: data.length,
itemBuilder: (BuildContext context, int position) {
return new ListTile(
title: new Text('${data[position]['name']}'),
);
}),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.person_add),
onPressed: () {
Navigator.of(context).pushNamed('/Add');
}),
);
}
}
Output Console
Performing hot restart...
Syncing files to device Android SDK built for x86...
Restarted application in 4,410ms.
I/flutter (10119): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (10119): The following NoSuchMethodError was thrown building HomePage(dirty, state: HomePageState#80635):
I/flutter (10119): The getter 'length' was called on null.
I/flutter (10119): Receiver: null
I/flutter (10119): Tried calling: length
I/flutter (10119):
I/flutter (10119): When the exception was thrown, this was the stack:
I/flutter (10119): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
I/flutter (10119): #1 HomePageState.build (package:json/main.dart:59:29)
I/flutter (10119): #2 StatefulElement.build (package:flutter/src/widgets/framework.dart:3809:27)
I/flutter (10119): #3 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3721:15)
I/flutter (10119): #4 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #5 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #6 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (10119): #7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #9 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #10 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (10119): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #13 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #14 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #15 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #16 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #18 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #19 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (10119): #20 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #22 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (10119): #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #25 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (10119): #26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #27 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #28 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (10119): #29 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #30 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #31 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #32 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #33 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #34 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (10119): #35 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #36 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #37 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #38 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #39 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #40 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #41 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #42 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #43 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #44 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #45 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #46 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #47 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (10119): #48 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #49 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #50 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #51 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (10119): #52 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #53 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #54 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #55 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #56 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #57 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #58 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #59 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #60 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (10119): #61 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #62 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #63 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #64 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #65 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #66 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (10119): #67 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #68 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #69 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #70 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #71 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #72 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #73 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #74 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #75 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #76 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (10119): #77 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #78 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #79 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #80 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #81 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #82 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #83 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #84 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #85 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #86 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #87 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #88 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (10119): #89 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #90 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #91 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #92 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #93 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #94 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #95 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (10119): #96 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #97 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #98 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4965:32)
I/flutter (10119): #99 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #100 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #101 _TheatreElement.mount (package:flutter/src/widgets/overlay.dart:493:16)
I/flutter (10119): #102 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #103 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #104 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #105 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #106 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #107 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (10119): #108 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #109 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #110 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #111 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #112 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #113 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #114 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #115 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #116 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #117 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (10119): #118 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #119 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #120 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #121 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #122 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #123 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (10119): #124 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #125 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #126 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #127 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (10119): #128 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #163 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #164 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #165 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #166 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #167 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #168 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #169 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #170 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #171 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #172 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #173 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #174 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #175 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #176 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #177 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #178 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #179 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (10119): #180 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #181 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #182 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #183 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #184 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #185 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (10119): #186 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #187 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #202 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #203 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #204 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #205 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #206 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #207 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #208 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #209 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #210 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #211 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #212 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #213 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #214 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #215 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #216 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #217 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #218 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #219 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #220 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #221 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #222 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #223 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (10119): #224 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #225 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #226 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #227 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #228 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #229 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #230 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #231 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #232 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #233 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #234 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #235 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #236 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (10119): #237 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #238 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #239 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #240 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (10119): #241 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (10119): #242 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (10119): #243 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (10119): #244 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (10119): #245 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (10119): #246 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:909:16)
I/flutter (10119): #247 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:880:5)
I/flutter (10119): #248 RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:826:17)
I/flutter (10119): #249 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2266:19)
I/flutter (10119): #250 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:825:13)
I/flutter (10119): #251 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:712:7)
I/flutter (10119): #252 runApp (package:flutter/src/widgets/binding.dart:756:7)
I/flutter (10119): #253 main (package:json/main.dart:8:16)
I/flutter (10119): #254 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:289:19)
I/flutter (10119): #255 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
I/flutter (10119): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (10119): [{_id: 5c55e837b1dee7326c4ba39d, create_date: 2019-02-02T18:57:59.406Z, name: Tariq, gender: male, email: ta#gmail.com, phone: 07954622145, __v: 0}, {_id: 5c55e86cb1dee7326c4ba39e, create_date: 2019-02-02T18:58:52.346Z, name: He, gender: Female, email: h#gmail.com, phone: 075554622145, __v: 0}, {_id: 5c55e890b1dee7326c4ba39f, create_date: 2019-02-02T18:59:28.108Z, name: Sh, gender: Female, email: sh#gmail.com, phone: 075654622145, __v: 0}, {_id: 5c584f60af32d00dec0facae, create_date: 2019-02-04T14:42:40.036Z, name: Emad, gender: male, email: emad#gmail.com, __v: 0}, {_id: 5c585236af32d00dec0facaf, create_date: 2019-02-04T14:54:46.734Z, name: Fa, gender: Female, email: Fa#gmail.com, phone: 075654622145, __v: 0}, {_id: 5c58605bcf4f4c3008e50a04, create_date: 2019-02-04T15:55:07.696Z, name: Fa, gender: Female, email: f #gmail.com, phone: 075654622145, __v: 0}]
when i run the code i got the data in the console, but the UI for mobile APP . i get the error
output
You need to guard against the case when data == null
body: new Center(
child: data == null ? Container() : new ListView.builder(
itemCount: data.length,
itemBuilder: (BuildContext context, int position) {
return new ListTile(
title: new Text('${data[position]['name']}'),
);
}),
),
The reason behind is If you are using a List and trying to get it's length while the list is null.
In order to remove the exception is to initialize the List data (in the above code) with some values (Before getting the required values).
What I did was just initialized the list with an empty array. like,
List _elements = [];
Comments please.
Answer by ABHIMANGAL MS was perfect for me.
We made a list data at the top of our page like:
list data;
This was null obv. We then ran json under it to get our data from an api and populate data with that info.
However the page would first load data while empty then make the api call.
Making data: list data = []; removed the error it would throw up for a second before loading the json data. so thank you !!!
For my own future reference when receiving this error during http POST requests, Flutter doesn't like sending null values in the body of the request. I was working with an API call that had a null requirement in the request - I simply ignored this and only sent the parameters that were non-null

Using Targetplatform causes layout problem

I am trying to check if user is on Iphone or Android
I am following this post to check
How do you detect the host platform from Dart code?
in my initState i have added the following check
typeOfDevice = Theme.of(context).platform == TargetPlatform.iOS
? "1"
: "2";
but whenever i tried to use that i get following error
I/flutter (22330): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (22330): The following assertion was thrown building MediaQuery(MediaQueryData(size: Size(360.0, 640.0),
I/flutter (22330): devicePixelRatio: 2.0, textScaleFactor: 1.0, padding: EdgeInsets(0.0, 24.0, 0.0, 0.0), viewInsets:
I/flutter (22330): EdgeInsets.zero, alwaysUse24HourFormat: false, accessibleNavigation: falsedisableAnimations:
I/flutter (22330): falseinvertColors: falseboldText: false)):
I/flutter (22330): inheritFromWidgetOfExactType(_InheritedTheme) or inheritFromElement() was called before
I/flutter (22330): _EnterOtpLoginState.initState() completed.
I/flutter (22330): When an inherited widget changes, for example if the value of Theme.of() changes, its dependent
I/flutter (22330): widgets are rebuilt. If the dependent widget's reference to the inherited widget is in a constructor
I/flutter (22330): or an initState() method, then the rebuilt dependent widget will not reflect the changes in the
I/flutter (22330): inherited widget.
I/flutter (22330): Typically references to to inherited widgets should occur in widget build() methods. Alternatively,
I/flutter (22330): initialization based on inherited widgets can be placed in the didChangeDependencies method, which
I/flutter (22330): is called after initState and whenever the dependencies change thereafter.
I/flutter (22330): When the exception was thrown, this was the stack:
I/flutter (22330): #0 StatefulElement.inheritFromElement.<anonymous closure> (package:flutter/src/widgets/framework.dart:3920:9)
I/flutter (22330): #1 StatefulElement.inheritFromElement (package:flutter/src/widgets/framework.dart:3953:6)
I/flutter (22330): #2 Element.inheritFromWidgetOfExactType (package:flutter/src/widgets/framework.dart:3274:14)
I/flutter (22330): #3 Theme.of (package:flutter/src/material/theme.dart:127:52)
I/flutter (22330): #4 _EnterOtpLoginState.initState (package:dice_clutter/screens/otp_login/otp_login.dart:126:26)
I/flutter (22330): #5 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3830:58)
I/flutter (22330): #6 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #7 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #8 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4965:32)
I/flutter (22330): #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #10 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4965:32)
I/flutter (22330): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #13 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #14 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #15 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #16 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #18 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #19 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #20 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #21 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #22 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #23 ParentDataElement.mount (package:flutter/src/widgets/framework.dart:4047:11)
I/flutter (22330): #24 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #25 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4965:32)
I/flutter (22330): #26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #27 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #28 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #29 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #30 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #31 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #32 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #33 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #35 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #36 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #37 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #38 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #39 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #40 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #41 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #42 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #43 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #44 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #45 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #46 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #47 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #48 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #49 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #50 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #51 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #52 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #53 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #54 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #55 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #56 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #57 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #58 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #59 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #60 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #61 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #62 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #63 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #64 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #65 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #66 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #67 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #68 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #69 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #70 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #71 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #72 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #73 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #74 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #75 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #76 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #77 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #78 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #79 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #80 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #81 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #82 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #83 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #84 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #85 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #86 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #87 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #88 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #89 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #90 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #91 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #92 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #93 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #94 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #95 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #96 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #97 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #98 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #99 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #100 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #101 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #102 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #103 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #104 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #105 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #106 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #107 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #108 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #109 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #110 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #111 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #112 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #113 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #114 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #115 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #116 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #117 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #118 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #119 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #120 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #121 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #122 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #123 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #124 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #125 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #126 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #127 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #128 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #129 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #130 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #131 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #132 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #133 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #134 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #135 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #136 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #137 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #138 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #139 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #140 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #141 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #142 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #143 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #144 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #145 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #146 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #147 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #148 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #149 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #150 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #151 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #152 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #153 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #154 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #155 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #156 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #157 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #158 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #159 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #160 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #161 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #162 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #163 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #164 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #165 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #166 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #167 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #168 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #169 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #170 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #171 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #172 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #173 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #174 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #175 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #176 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #177 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #178 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #179 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #180 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #181 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #182 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #183 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #184 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #185 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #186 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #187 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #188 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #189 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #190 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #191 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #192 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #193 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #194 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #195 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4643:32)
I/flutter (22330): #196 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4975:17)
I/flutter (22330): #197 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #198 _TheatreElement.update (package:flutter/src/widgets/overlay.dart:507:16)
I/flutter (22330): #199 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #200 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #201 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #202 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (22330): #203 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #204 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #205 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #206 ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
I/flutter (22330): #207 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #208 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (22330): #209 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #210 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #211 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #212 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (22330): #213 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #214 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (22330): #215 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #216 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (22330): #217 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #218 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #219 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #220 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2286:33)
I/flutter (22330): #221 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:676:20)
I/flutter (22330): #222 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
I/flutter (22330): #223 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (22330): #224 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (22330): #225 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (22330): #226 _invoke (dart:ui/hooks.dart:154:13)
I/flutter (22330): #227 _drawFrame (dart:ui/hooks.dart:143:3)
I/flutter (22330): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (22330): Another exception was thrown: The _ScaffoldLayout custom multichild layout delegate forgot to lay out the following child:
I/flutter (22330): Another exception was thrown: inheritFromWidgetOfExactType(_InheritedTheme) or inheritFromElement() was called before _EnterOtpLoginState.initState() completed.
I/flutter (22330): Another exception was thrown: The _ScaffoldLayout custom multichild layout delegate forgot to lay out the following children:
when i comment that line of code the app runs fine
This issue happens because you're trying to obtain an Inheritedwidget from initState. Which is purposefully not possible
Instead use didChangeDependencies:
didChangeDependencies() {
typeOfDevice = Theme.of(context).platform == TargetPlatform.iOS
}

Another exception was thrown: No TabController for TabBar

I am adding bottom tab bar to my flutter app. But after adding the code it is throwing me an error.
Here is my code:
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: new Text("Tab App."),
),
drawer: sideDrawer(),
bottomNavigationBar: bottomTabBar()
);
}
//Bottom Tab Bar
Widget bottomTabBar(){
return new TabBarView(
children:[
new Container(
color: Colors.yellow,
),
new Container(
color: Colors.orange,
),
new Container(
color: Colors.lightGreen,
),
new Container(
color: Colors.red,
)
],
);
}
Here is error:
flutter: When the exception was thrown, this was the stack:
flutter: #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
flutter: #1 _HomeState.drawerHeader (package:tabApp/screens/home.dart:72:40)
flutter: #2 _HomeState.sideDrawer (package: tabApp/screens/home.dart:91:13)
flutter: #3 _HomeState.build (package:tabApp/screens/home.dart:37:15)
flutter: #4 StatefulElement.build (package:flutter/src/widgets/framework.dart:3809:27)
flutter: #5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3721:15)
flutter: #6 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #7 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #8 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
flutter: #9 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #11 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #12 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #13 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #14 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #15 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #16 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #17 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #18 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #19 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #20 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #21 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #22 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #23 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #24 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #25 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #26 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4965:32)
flutter: #27 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #28 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #30 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #31 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #32 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
flutter: #33 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #34 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #35 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #36 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #37 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #38 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #39 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #40 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #41 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #42 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
flutter: #43 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #44 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #45 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #46 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #47 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #48 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #49 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #50 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #51 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #52 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
flutter: #53 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #54 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #55 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #56 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #57 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #58 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #59 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #60 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #61 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #62 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
flutter: #63 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #64 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #65 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #66 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #67 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #68 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #69 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #70 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #71 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #72 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #73 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #74 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #75 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
flutter: #76 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #77 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #78 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #79 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #80 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #81 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #82 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #83 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #84 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #85 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #86 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #87 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #88 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #89 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #90 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #91 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #92 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #93 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #94 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
flutter: #95 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #96 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #97 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #98 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #99 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #100 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #101 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #102 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #103 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #104 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #105 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #106 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #107 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #108 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #109 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #110 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #111 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #112 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #113 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #114 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #115 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #116 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
flutter: #117 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #118 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #119 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #120 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #121 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #122 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #123 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
flutter: #124 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #125 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #126 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #127 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4643:32)
flutter: #128 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4975:17)
flutter: #129 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #130 _TheatreElement.update (package:flutter/src/widgets/overlay.dart:507:16)
flutter: #131 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #132 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #133 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #134 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
flutter: #135 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #136 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #137 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #138 ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
flutter: #139 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #140 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #141 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #142 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #143 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #144 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
flutter: #145 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #146 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #147 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #148 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #149 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #150 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #151 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #152 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2286:33)
flutter: #153 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:676:20)
flutter: #154 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
flutter: #155 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
flutter: #156 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
flutter: #157 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
flutter: #158 _invoke (dart:ui/hooks.dart:154:13)
flutter: #159 _drawFrame (dart:ui/hooks.dart:143:3)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: No TabController for TabBarView.
As The Error is Stating you need - TabController Edit Your Code as Below.
#override
Widget build(BuildContext context) {
// TODO: implement build
return DefaultTabController( // Added
length: 4, // Added
initialIndex: 0, //Added
child: Scaffold(
appBar: AppBar(
title: new Text("Tab App."),
),
drawer: sideDrawer(context), // Passed BuildContext in function.
bottomNavigationBar: bottomTabBar()),
);
}
Widget sideDrawer(BuildContext context){ ......

preload assets images before build

am trying to set background image of my container to image from assets like this:
return new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage(images[index]),
fit: BoxFit.cover,
),
),
but this will take some time to load and return blank whilte screen till image load ..
so i tried to preload images before build like this:
#override
void initState() {
precacheImage(new AssetImage(images[1]), context);
precacheImage(new AssetImage(images[2]), context);
precacheImage(new AssetImage(images[3]), context);
super.initState();
}
and this returned this error:
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building Builder:
flutter: inheritFromWidgetOfExactType(MediaQuery) or inheritFromElement() was called before
flutter: _WalkthroughPageState.initState() completed.
flutter: When an inherited widget changes, for example if the value of Theme.of() changes, its dependent
flutter: widgets are rebuilt. If the dependent widget's reference to the inherited widget is in a constructor
flutter: or an initState() method, then the rebuilt dependent widget will not reflect the changes in the
flutter: inherited widget.
flutter: Typically references to to inherited widgets should occur in widget build() methods. Alternatively,
flutter: initialization based on inherited widgets can be placed in the didChangeDependencies method, which
flutter: is called after initState and whenever the dependencies change thereafter.
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 StatefulElement.inheritFromElement. (package:flutter/src/widgets/framework.dart:3898:9)
flutter: #1 StatefulElement.inheritFromElement (package:flutter/src/widgets/framework.dart:3931:6)
flutter: #2 Element.inheritFromWidgetOfExactType (package:flutter/src/widgets/framework.dart:3274:14)
flutter: #3 MediaQuery.of (package:flutter/src/widgets/media_query.dart:476:38)
flutter: #4 createLocalImageConfiguration (package:flutter/src/widgets/image.dart:49:34)
flutter: #5 precacheImage (package:flutter/src/widgets/image.dart:81:37)
flutter: #6 _WalkthroughPageState.initState (package:spl/Pages/walkthrough.page.dart:65:5)
flutter: #7 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3808:58)
flutter: #8 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3674:5)
flutter: #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #10 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #11 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #12 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #13 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3679:5)
flutter: #14 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3674:5)
flutter: #15 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #16 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #17 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4838:14)
flutter: #18 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #19 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #20 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4838:14)
flutter: #21 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #22 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #23 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4838:14)
flutter: #24 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #25 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #26 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #27 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #28 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3679:5)
flutter: #29 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3826:11)
flutter: #30 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3674:5)
flutter: #31 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #32 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #33 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4838:14)
flutter: #34 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #35 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #36 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #37 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #38 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3679:5)
flutter: #39 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3674:5)
flutter: #40 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #41 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #42 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4838:14)
flutter: #43 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #44 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #45 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #46 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #47 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3679:5)
flutter: #48 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3826:11)
flutter: #49 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3674:5)
flutter: #50 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #51 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #52 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #53 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #54 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3679:5)
flutter: #55 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3674:5)
flutter: #56 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #57 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #58 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4838:14)
flutter: #59 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #60 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #61 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #62 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #63 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3679:5)
flutter: #64 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3674:5)
flutter: #65 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #66 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #67 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #68 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #69 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3679:5)
flutter: #70 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3826:11)
flutter: #71 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3674:5)
flutter: #72 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #73 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #74 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #75 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #76 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3679:5)
flutter: #77 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3826:11)
flutter: #78 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3674:5)
flutter: #79 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #80 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #81 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4621:32)
flutter: #82 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4953:17)
flutter: #83 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #84 _TheatreElement.update (package:flutter/src/widgets/overlay.dart:507:16)
flutter: #85 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #86 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #87 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #88 StatefulElement.update (package:flutter/src/widgets/framework.dart:3856:5)
flutter: #89 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #90 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #91 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #92 ProxyElement.update (package:flutter/src/widgets/framework.dart:3968:5)
flutter: #93 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #94 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4845:14)
flutter: #95 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #96 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #97 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #98 StatefulElement.update (package:flutter/src/widgets/framework.dart:3856:5)
flutter: #99 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #100 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4845:14)
flutter: #101 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #102 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4845:14)
flutter: #103 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #104 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3710:16)
flutter: #105 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #106 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2286:33)
flutter: #107 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:676:20)
flutter: #108 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
flutter: #109 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
flutter: #110 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
flutter: #111 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
flutter: #112 _invoke (dart:ui/hooks.dart:151:13)
flutter: #113 _drawFrame (dart:ui/hooks.dart:140:3)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
I had the same problem, the solution was in the error description itself:
initialization based on inherited widgets can be placed in the didChangeDependencies method, which is called after initState and
whenever the dependencies change thereafter.
Here's a simplified version of my code, preloading images in method didChangeDependencies:
class _SampleWidgetState extends State<SamleWidget> {
Image image1;
Image image2;
Image image3;
Image image4;
Image currentImage;
#override
void initState() {
super.initState();
image1 = Image.asset("assets/image1.png");
image2 = Image.asset("assets/image2.png");
image3 = Image.asset("assets/image3.png");
image4 = Image.asset("assets/image4.png");
currentImage = image1;
}
#override
void didChangeDependencies() {
super.didChangeDependencies();
precacheImage(image1.image, context);
precacheImage(image2.image, context);
precacheImage(image3.image, context);
precacheImage(image4.image, context);
}
#override
Widget build(BuildContext context) {
return Container(
child: currentImage,
);
}
void setImage(int index) {
switch (index) {
case 1: currentImage = image1; break;
case 2: currentImage = image2; break;
case 3: currentImage = image3; break;
case 4: currentImage = image4; break;
}
}
}
Hope this helps :)
I'm not sure, but I think, you can try FutureBuilder
import 'dart:ui' as ui;
class MyImage extends StatelessWidget {
MyImage(this._imgSrc);
final String _imgSrc;
#override
Widget build(BuildContext context) {
Image image = Image.asset(_imgSrc);
Completer<ui.Image> completer = new Completer<ui.Image>();
image.image.resolve(ImageConfiguration()).addListener((ImageInfo info, bool _) {
completer.complete(info.image);
});
return FutureBuilder(
future: completer.future,
builder: (context, AsyncSnapshot<ui.Image> snapshot) {
return snapshot.hasData ? image : Container();
});
}
This is happening because precacheImage is creating an ImageConfiguration object with the function createLocalImageConfiguration. And this function accesses some InheritedWidget.
And accessing InheritedWidget in constructor or in the initState method can be tricky.
Here is the createLocalImageConfiguration function, the one that access InheritedWidget
ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size? size }) {
return ImageConfiguration(
bundle: DefaultAssetBundle.of(context),
devicePixelRatio: MediaQuery.maybeOf(context)?.devicePixelRatio ?? 1.0,
locale: Localizations.maybeLocaleOf(context),
textDirection: Directionality.maybeOf(context),
size: size,
platform: defaultTargetPlatform,
);
}
To avoid this, as the error message advise you and as Alex Domenici answered, you can move this code inside the didUpdateWidget method.

Error: '_elements.contains(element)': is not true

I am seeing this error '_elements.contains(element)': is not true.for the past two days in my flutter project, this was working absolutely fine since the beginning. I am sorry to say this but I have no clue regarding this error but i think i am missing something which is causing this error. Also, when I hot reload the same page the layout is populated, but throws the exceptions.
Intermittently this was also showing Duplicate GlobalKeys() detected, but this wasn't the case in the beginning.
Please can someone help me if they stumbled upon these errors before. I couldn't really write an example to reproduce the same problem. Many thanks.
I have given the error details as follows:
Performing hot reload...
I/flutter (22248): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════
I/flutter (22248): The following assertion was thrown building
TickerMode(mode: disabled):
I/flutter (22248): 'package:flutter/src/widgets/framework.dart': Failed
assertion: line 1766 pos 12:
I/flutter (22248): '_elements.contains(element)': is not true.
I/flutter (22248):
I/flutter (22248): Either the assertion indicates an error in the framework
itself, or we should provide substantially
I/flutter (22248): more information in this error message to help you
determine and fix the underlying cause.
I/flutter (22248): In either case, please report this assertion by filing a
bug on GitHub:
I/flutter (22248): https://github.com/flutter/flutter/issues/new
I/flutter (22248):
I/flutter (22248): When the exception was thrown, this was the stack:
I/flutter (22248): #2 _InactiveElements.remove
(package:flutter/src/widgets/framework.dart:1766:12)
I/flutter (22248): #3 Element._retakeInactiveElement
(package:flutter/src/widgets/framework.dart:2850:29)
I/flutter (22248): #4 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2873:32)
I/flutter (22248): #5 Element.updateChild
(package:flutter/src/widgets/framework.dart:2688:12)
I/flutter (22248): #6 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #7 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #8 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #9 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #10 RenderObjectElement.updateChildren
(package:flutter/src/widgets/framework.dart:4262:32)
I/flutter (22248): #11 _TheatreElement.update
(package:flutter/src/widgets/overlay.dart:508:17)
I/flutter (22248): #12 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #13 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #14 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #15 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #16 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #17 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #18 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #19 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #20 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #21 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4535:14)
I/flutter (22248): #22 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #23 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #24 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #25 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #26 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #27 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4535:14)
I/flutter (22248): #28 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #29 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4535:14)
I/flutter (22248): #30 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #31 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #32 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #33 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #34 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #35 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #36 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #37 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #38 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #39 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4535:14)
I/flutter (22248): #40 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #41 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #42 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #43 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3607:5)
I/flutter (22248): #44 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #45 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #46 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #47 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3607:5)
I/flutter (22248): #48 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #49 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #50 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #51 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3607:5)
I/flutter (22248): #52 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #53 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #54 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #55 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3607:5)
I/flutter (22248): #56 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #57 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #58 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #59 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #60 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #61 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #62 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #63 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #64 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #65 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #66 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #67 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #68 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #69 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #70 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #71 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #72 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #73 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #74 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #75 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #76 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #77 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #78 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #79 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #80 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #81 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #82 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #83 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #84 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #85 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #86 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #87 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3607:5)
I/flutter (22248): #88 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #89 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #90 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #91 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #92 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #93 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #94 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #95 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #96 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #97 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #98 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #99 BuildOwner.buildScope
(package:flutter/src/widgets/framework.dart:2246:33)
I/flutter (22248): #100
BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&Renderer
Binding&WidgetsBinding.drawFrame
(package:flutter/src/widgets/binding.dart:580:20)
I/flutter (22248): #101
BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&Renderer
Binding._handlePersistentFrameCallback
(package:flutter/src/rendering/binding.dart:200:5)
I/flutter (22248): #102
BindingBase&SchedulerBinding._invokeFrameCallback
(package:flutter/src/scheduler/binding.dart:713:15)
I/flutter (22248): #103 BindingBase&SchedulerBinding.handleDrawFrame
(package:flutter/src/scheduler/binding.dart:649:9)
I/flutter (22248): #104
BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&Renderer
Binding.scheduleWarmUpFrame.<anonymous closure>
(package:flutter/src/rendering/binding.dart:286:20)
I/flutter (22248): #106 _Timer._runTimers (dart:isolate-
patch/dart:isolate/timer_impl.dart:367)
I/flutter (22248): #107 _Timer._handleMessage (dart:isolate-
patch/dart:isolate/timer_impl.dart:401)
I/flutter (22248): #108 _RawReceivePortImpl._handleMessage
(dart:isolate-patch/dart:isolate/isolate_patch.dart:163)
I/flutter (22248): (elided 3 frames from class _AssertionError and
package dart:async-patch)
I/flutter (22248):
══════════════════════════════════════════════════════════════════════════
══════════════════════════
Reloaded 0 of 492 libraries in 823ms.
I have included a sample example of what i am trying to do in my application.
main.dart
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:untitled3/secondwidget.dart';
void main() {
runApp(
new Example(),
);
}
class Example extends StatefulWidget {
#override
_ExampleState createState() => new _ExampleState();
}
class _ExampleState extends State<Example> {
int noOfBranches;
#override
void initState() {
super.initState();
getCount();
}
void getCount() {
print('list builder count is ${noOfBranches}');
}
#override
Widget build(BuildContext context) {
setState(() {
noOfBranches = 2;
});
return new MaterialApp(
home: new Scaffold(
body: new ListView.builder(
itemCount: noOfBranches,
itemBuilder: (BuildContext context, int index) {
return new Card(
child: new FlatButton(
onPressed: (() {
Navigator.push(
context,
new MaterialPageRoute(
builder: (_) => new SecondWidget()));
}),
child: new Text('Next Widget')),
);
}),
),
);
}
}
secondwidget.dart
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class SecondWidget extends StatefulWidget {
#override
_SecondWidgetState createState() => new _SecondWidgetState();
}
class _SecondWidgetState extends State<SecondWidget> {
#override
Widget build(BuildContext context) {
return new Container(
child: new Text('Second Widget'),
);
}
}
I don't see the error in my application if setState() declare as given in the example main.dart file inside the
#override
Widget build(BuildContext context) {
setState(() {
noOfBranches = 2;
});
.....
}
but I only see this error if I declare the setState() inside the getCount() function.
I am not so sure why this is the case.
I am actually stuck on this error for two days and any help would be greatly appreciated.
Many Thanks,
Mahi
I think I kinda solved the error by declaring the setState() inside the
#override
Widget build(BuildContext context) {
setState(() {
noOfBranches = 2;
});
print('noof branches inside widget build = $noOfBranches');
.....
}
Now the app is running absolutely fine without any problems.
But, I would be grateful if there are any more suggestions as I am new to programming and would be very very happy to learn more.
The only problem was the setState() was modifying the context and when clicked on the button to call another widget it was throwing up with this error message.
Many Thanks,
Mahi.
Why don't you set your noOfBranches variable not in the initState method?
#override
void initState() {
super.initState();
noOfBranches = 2;
}

Resources