skip to Main Content

I am facing this error, even though I have written the ‘if statement’.

I also tried adding an ‘else statement’ like else{return Text(" "); } but then it completely ignores the ‘if statement’ and shows only the else statement in the Output, which is a Text widget.

enter image description here

I am also facing this error in the file ‘db_helper.dart’ when writing await dbClient!.query('cart');
enter image description here

2

Answers


  1. The solution to the first error is return something both in if and else condition like this:

    if(snapshot.hasData){
       return Expanded();
     }else{
      return Text("");
     }
    

    and for the 2nd error make the code like this:

    final List<Map<String, Object?>> queryResult=await dbClient!.query("cart");
    
    Login or Signup to reply.
  2. The issue with your first snippet is that you return a Widget only when snapshot.hasData, to solve this after that return outside of the if case, either return a SizedBox or a CircularProgressIndicator that will show loading until the Future yilds data.

    The second snippet indicates that your return type does not match with the type of queryResult, so you can change the type of queryResult to List<Map<String, Object?>> and this will most probably fix all your errors.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search