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.
I am also facing this error in the file ‘db_helper.dart’ when writing await dbClient!.query('cart');
2
Answers
The solution to the first error is return something both in if and else condition like this:
and for the 2nd error make the code like this:
The issue with your first snippet is that you return a
Widget
only whensnapshot.hasData
, to solve this after thatreturn
outside of theif
case, eitherreturn
aSizedBox
or aCircularProgressIndicator
that will show loading until theFuture
yilds data.The second snippet indicates that your return type does not match with the type of
queryResult
, so you can change the type ofqueryResult
toList<Map<String, Object?>>
and this will most probably fix all your errors.