1
How can I check if a return async
of a particular sqlite
is empty?
I need to check if the "resultReceita" is null before displaying it in the widget.
I tried with an if however, I did not succeed. This code works perfectly, but when the user installs for the first time he has not made releases, thus returns a "null" error in futurebuilder.
My code:
@override
Widget build(BuildContext context) {
//FUTURE BUILDER PARA EXIBIR SALDO CONTAS
Future<int> _query() async {
var db = await DatabaseHelper.instance.database;
var resultReceita = await db.rawQuery('SELECT SUM(valor) FROM lancamentos WHERE tipo = "R"');
var resultDespesa = await db.rawQuery('SELECT SUM(valor) FROM lancamentos WHERE tipo = "D"');
if (resultReceita == null) {
print("Esta vazio");
} else {
print("Não vazio");
}
print('resultado $resultReceita');
print('teste2 $resultDespesa[0]');
return resultReceita[0]["SUM(valor)"] - resultDespesa[0]["SUM(valor)"];
}
Please put your formatted code exactly as you are using it (the one you posted wouldn’t even compile, are missing {}keys), and also put the stacktrace of the error that is occurring.
– Julio Henrique Bitencourt