Reputation: 769
I guess I am blind, but I can not see the problem... Maybe someone can help me.
The Problem is in this line "onRefresh: updateData()" and the full message is "The argument type 'Future' can't be assigned to the parameter type 'Future Function()'."
late Future<DocumentSnapshot> dataFuture;
Future<void> updateData() async {
setState(() {
dataFuture = getData();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: RefreshIndicator(
onRefresh: updateData(),
...
Upvotes: 0
Views: 2484
Reputation: 2701
onRefresh: () async {
updateData();
return Future.delayed(const Duration(seconds: 1));
}
void updateData() async {
setState(() {
dataFuture = getData();
});
}
Upvotes: 0
Reputation: 999
If you want to use async
and await
then,
Replace,
onRefresh: updateData(),
To,
onRefresh: () async {
await updateData();
},
Upvotes: 1
Reputation: 1537
I think the problem is that you're calling the function rather than providing it as an argument - should be just updateData
rather than updateData()
.
onRefresh
expects a callback (a function) which would then be executed upon a refresh event. Here dart is telling you that you are providing the wrong argument type - a Future
(the result of calling updateData
) instead of a function.
Upvotes: 3