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(),
...
CodePudding user response:
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.
CodePudding user response:
If you want to use async
and await
then,
Replace,
onRefresh: updateData(),
To,
onRefresh: () async {
await updateData();
},
CodePudding user response:
onRefresh: () async {
updateData();
return Future.delayed(const Duration(seconds: 1));
}
void updateData() async {
setState(() {
dataFuture = getData();
});
}