I am working on a project where I am creating the selecting interests screen where user can select 5 interests. I am getting interest after calling the API and then I got id and value (value is the title of interest) if the user selects following interest i have to send corresponding id's to the backend. I created the function of getData to get List<Map<String, dynamic>> options
and then call it in initstate but getting the below mentioned error. I need help in solving the following problem. Thank you.
Code:
List<Map<String, dynamic>> options = [];
void getData() async {
List<Map<String, dynamic>> tempData = [];
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return Center(
child: LoadingAnimationWidget.discreteCircle(
color: const Color(0XFF00B251),
size: 50,
secondRingColor: const Color(0XFFF8B32B),
thirdRingColor: const Color(0XFFF72A37),
),
);
},
);
var response = await Auth().getInterests();
Navigator.pop(context);
if (response['statusCode'] == 200) {
for (int i = 0; i < response['data'].length; i++) {
tempData.add({
'id': response['data'][i]['_id'],
'value': response['data'][i]['title']
});
}
} else {
displayErrorMotionToast(context, response['message']);
}
setState(() {
options = tempData;
});
}
@override
void initState() {
getData();
super.initState();
}
//UI CODE
Wrap(
children: options.map(
(value) {
bool isSelected = false;
if (interests.contains(value['id'])) {
isSelected = true;
}
return GestureDetector(
onTap: () {
if (!interests.contains(value['id'])) {
if (interests.length < 5) {
interests.add(value['id']);
setState(() {});
}
} else {
interests
.removeWhere((element) => element == value['id']);
setState(() {});
}
},
child: Container(
margin: const EdgeInsets.symmetric(
horizontal: 7.5,
vertical: 5,
),
padding: const EdgeInsets.symmetric(
... ),
decoration: BoxDecoration(
...
),
child: Text(
value['value'],
style: TextStyle(
...
),
)),
);
},
).toList(),
),
Error:
E/flutter ( 5404): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: dependOnInheritedWidgetOfExactType<_LocalizationsScope>() or dependOnInheritedElement() was called before _InterestState.initState() completed.
E/flutter ( 5404): When an inherited widget changes, for example if the value of Theme.of() changes, its dependent widgets are rebuilt. If the dependent widget's reference to the inherited widget is in a constructor or an initState() method, then the rebuilt dependent widget will not reflect the changes in the inherited widget.
E/flutter ( 5404): Typically references to inherited widgets should occur in widget build() methods. Alternatively, initialization based on inherited widgets can be placed in the didChangeDependencies method, which is called after initState and whenever the dependencies change thereafter.
E/flutter ( 5404): #0 StatefulElement.dependOnInheritedElement.<anonymous closure> (package:flutter/src/widgets/framework.dart:5704:9)
E/flutter ( 5404): #1 StatefulElement.dependOnInheritedElement (package:flutter/src/widgets/framework.dart:5747:6)
E/flutter ( 5404): #2 Element.dependOnInheritedWidgetOfExactType (package:flutter/src/widgets/framework.dart:4765:14)
E/flutter ( 5404): #3 Localizations.of (package:flutter/src/widgets/localizations.dart:529:48)
E/flutter ( 5404): #4 debugCheckHasMaterialLocalizations.<anonymous closure> (package:flutter/src/material/debug.dart:92:23)
E/flutter ( 5404): #5 debugCheckHasMaterialLocalizations (package:flutter/src/material/debug.dart:113:4)
E/flutter ( 5404): #6 showDialog (package:flutter/src/material/dialog.dart:1413:10)
E/flutter ( 5404): #7 _InterestState.getData (package:communify/Screens/Registration/Sign%20Up/interests.dart:66:5)
E/flutter ( 5404): #8 _InterestState.initState (package:communify/Screens/Registration/Sign%20Up/interests.dart:131:5)
E/flutter ( 5404): #9 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5602:55)
E/flutter ( 5404): #10 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #13 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6736:14)
E/flutter ( 5404): #14 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #15 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #16 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #17 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #18 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #19 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #20 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #22 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6736:14)
E/flutter ( 5404): #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #25 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6736:14)
E/flutter ( 5404): #26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #27 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #28 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #29 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #30 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #31 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #32 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #33 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #34 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #35 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #36 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6736:14)
E/flutter ( 5404): #37 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #38 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #39 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #40 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #41 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #42 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #43 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #44 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #45 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #46 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #47 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6736:14)
E/flutter ( 5404): #48 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #49 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #50 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #51 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #52 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #53 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #54 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #55 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #56 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #57 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #58 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #59 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #60 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #61 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #62 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #63 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #64 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #65 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #66 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6736:14)
E/flutter ( 5404): #67 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #68 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #69 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #70 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #71 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #72 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #73 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #74 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #75 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #76 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #77 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6736:14)
E/flutter ( 5404): #78 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #79 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #80 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #81 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #82 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #83 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #84 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #85 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #86 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #87 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #88 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #89 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #90 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #91 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #92 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #93 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #94 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #95 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #96 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #97 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #98 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #99 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #100 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #101 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #102 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #103 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #104 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #105 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #106 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #107 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #108 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #109 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #110 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6736:14)
E/flutter ( 5404): #111 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #112 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #113 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #114 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #115 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #116 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #117 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #118 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #119 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6736:14)
E/flutter ( 5404): #120 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #121 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #122 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #123 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #124 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #125 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #126 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #127 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #128 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #129 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #130 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #131 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #132 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #133 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #134 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #135 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #136 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #137 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #138 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #139 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #140 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #141 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #142 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #143 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #144 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #145 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #146 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #147 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #148 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #149 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #150 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #151 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #152 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #153 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #154 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #155 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #156 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #157 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #158 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #159 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #160 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #161 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #162 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6736:14)
E/flutter ( 5404): #163 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #164 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #165 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #166 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #167 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #168 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #169 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #170 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #171 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #172 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #173 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #174 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #175 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #176 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #177 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #178 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #179 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #180 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #181 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #182 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #183 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #184 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #185 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #186 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #187 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #188 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #189 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #190 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #191 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #192 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
E/flutter ( 5404): #193 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
E/flutter ( 5404): #194 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
E/flutter ( 5404): #195 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
E/flutter ( 5404): #196 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5453:5)
E/flutter ( 5404): #197 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5625:11)
E/flutter ( 5404): #198 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
E/flutter ( 5404): #199 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
E/flutter ( 5404): #200 Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
Ideally Such Tasks can be done using the business logic and in the builder method. But we don't live in an ideal world?
Solution to your problem is simply to let the first frame of UI to render first.
WidgetsBinding.instance.addPostFrameCallback((_) => getData());
Use this in your initState
.
Quoting this from https://ankitgg66.medium.com/addpostframecallback-338316ca3207
The addPostFrameCallback method is a part of the WidgetsBinding class which is inherited from SchedulerBinding in Flutter. It allows developers to register a callback that will be invoked after the current frame finishes rendering. The callback receives a timestamp parameter indicating the time at which it was called.