I want to extract the future object from the http request so that I can use it as a regular object in the widget. How can I achieve this? (abstract code example below)
class _SomePageState extends State<SomePage> {
Data? _data;
@override
void initState() {
_loadData();
super.initState();
}
void _loadData() async {
await Service.getData().then((value) {
setState(() {
_data = value;
});
});
}
@override
Widget build(BuildContext context) {
//further use of the _data variable
}
}
In this case i'll have lateInitialization Error. In general, I would like to hear brief recommendations for working with future objects with explanations. Thanks