skip to Main Content

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


  1. I guess, your GetWaterDrankStored() method is returning something else, but not int. And you are getting an error when you are trying to call this method. Make sure your method returns Future<int>.

    Login or Signup to reply.
  2. It seems like you did not provide a return value to your async method. This return value should be a future. Please try this:

      int TotalWaterDrank = 0;
    
      Future<int> addedWater()  async{
        TotalWaterDrank = await WaterButtonsGrouped().getWaterDrankStored();
        setState(() {
    
        });
        return  TotalWaterDrank;
      }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search