I have an where i cant pass on the value obtained from my sqflight db to my method in a stateless function. My db works and i obtain the right value which i checked through the print function no issue here.
for context in dbhelper:
static Future <int> getWaterDrank() async {
final db = await WaterDBHelper.db();
List result = await db.rawQuery(
"SELECT * FROM $tableName WHERE ${columnDate} = ?", [dateCurrent]
);
print('this is the result $result');
String waterDrank = result[0]
.entries
.firstWhere((element) => element.key == 'waterDrank')
.value.toString();
print('this is what we are after ${int.parse(waterDrank)}');
return int.parse(waterDrank);
}
this is my stateless widget, where there is this function in charge of deriving value from db. for some reason i get it as zero even though the print function in dbhelper displays a value.
getWaterDrankStored() async {
int waterStoredValueInteger = await WaterDBHelper.getWaterDrank();
return waterStoredValueInteger;
}
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>
.