Alena
Alena

Reputation: 1214

Flutter: Sqflite firstintvalue returns null

I have rawQuery which returns sum of a column, it returns correct value. But when I try to access that value using Sqflite.firstIntValue(result);, it returns null.

Here is my code:

String query = "SELECT SUM(pay.fees) FROM payments pay"; 

final results = await db.rawQuery(query);

print(Sqflite.firstIntValue(results));    //prints null

print(results);                           //prints [{SUM(pay.fees): 807650.0}]

There is one thing strange about this, we delivered this app last October and it was working absolutely fine till last week, it broke all of sudden. It took me several days to make my last working code compatible with latest flutter.

Question:

  1. How can I fix this and get actual value?

  2. Any clue why it broke all of sudden?

Upvotes: 1

Views: 1409

Answers (1)

Atlas_Gondal
Atlas_Gondal

Reputation: 2552

Try following code:

String query = "SELECT SUM(pay.fees) as TOTAL FROM payments pay"; //create an alias

final results = await db.rawQuery(query);

print(results[0]['TOTAL']); //use alias to get results

Upvotes: 3

Related Questions