I need to initialize
Future<List<DataRow>> myrow = [];
I need to construct a table based on a future list.
Right now, I get the message:
A value of type ‘List’ can’t be assigned to a variable of type ‘Future<List>’
Thank you
I need to initialize
Future<List<DataRow>> myrow = [];
I need to construct a table based on a future list.
Right now, I get the message:
A value of type ‘List’ can’t be assigned to a variable of type ‘Future<List>’
Thank you
3
Answers
The error occurs because
Future<List<DataRow>>
expects a future (an asynchronous value) rather than a direct list. To initialize it properly, you need to assign a future or use an asynchronous function to fetch or construct the dataWhen you got a function that return a Future<List>, this mean two things:
First, the function is asynchronous and may not return immediately ans second the type of the return value is List.
So if you have a function prototype like this one:
you have to get the return value to do this:
The await keyword instruct to wait for myFunction return.
You can also use .then in order to wait myFunction completion :