class _MyHomePageState extends State<MyHomePage> {
DetailList detailList;
HeaderMatch headerMatch;
bool _loading; // Add this variable
// for Header Match
Future<DetailList> fetchHeader() async {
final response =
await http.get('http://placaresportivo.net:5000/api/demo/fixtures/id/83');
if (response.statusCode == 200) {
// If the call to the server was successful, parse the JSON.
setState(() {
headerMatch = HeaderMatch.fromJson(json.decode(response.body));
fetchPost();
_loading = false; // set it to false...
return headerMatch;
});
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load post');
}
}..........
@override
void initState() {
setState(() {
_loading = true;
});
this.fetchHeader();
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Color(0xff2c2840),
automaticallyImplyLeading: true,
title: Center(
child: appBarWidget(),
),
),
body: _buildWrapper(context) // This trailing comma makes auto-formatting nicer for build methods.
),
);
}
Widget _buildWrapper(BuildContext context) {
if(_loading) {
return Center(child: CircularProgressIndicator(),);
}else {
return bodyWidget();
}
}
...
.....
.......
I want to initialize data before build method so i override initState method and do my initialization stuff, but when i run the app then build method is called before initState method that's why it gives me the error "The getter 'game' was called on null.". i don't know what to do now. Attached file is my main.dart
--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/CABOCyWOYDGX9gajbuVXepGx9%3DUk8ocvAdNMR73wXWUYL3NMCgA%40mail.gmail.com.