I have a parameter that is a type Future in my main page- the value is obtained in a different page but not significant.
class Water extends StatefulWidget {
const Water({super.key});
@override
State<Water> createState() => _WaterState();
}
class _WaterState extends State<Water> {
int TotalWaterDrank = 0;
addedWater() async{
TotalWaterDrank = await WaterButtonsGrouped().getWaterDrankStored();
setState(() {
});
return TotalWaterDrank;
}
//in a children widget
Container(
width: 300,
height: 300,
child: WaterProgressIndicator(WaterDrank: addedWater()),
),
now in the WaterProgressIndicator page, i want to pass the value stored in addedWater() – which is a Future
class WaterProgressIndicator extends StatefulWidget {
Future WaterDrank;
WaterProgressIndicator({
required this.WaterDrank,
});
@override
State<WaterProgressIndicator> createState() => _WaterProgressIndicatorState(WaterDrank);
}
however i cant do this because the value im passing is not an int and i get the error above. I know i am meant to change "WaterDrank" but not sure how to go about it. I am also sure i definetly cant change the value of
2
Answers
I guess, your
GetWaterDrankStored()
method is returning something else, but notint
. And you are getting an error when you are trying to call this method. Make sure your method returnsFuture<int>
.It seems like you did not provide a return value to your async method. This return value should be a future. Please try this: