Search code examples
flutterdartsqflite

flutter - type 'QueryRow' is not a subtype of type 'String'


type 'QueryRow' is not a subtype of type 'String' when I retrieved data from sqflite, and I want to add it to widget

Future<List> getSpecificForm({String tableName, formId}) async { 
  final db = await database; 
  final List<Map<String, dynamic>> result = await db.rawQuery( 'SELECT * FROM $tableName WHERE id=? ORDER BY id DESC', [formId]); 
  return result; 
} 

Solution

  • Finally, I changed the function like this:

    Future<List> getSpecificForm({String tableName, formId}) async {
        final db = await database;
        final List<Map<String, dynamic>> result =  await db.rawQuery('SELECT * FROM $tableName WHERE id=?', [formId]);
    
        return List<Map<String, dynamic>>.generate(
            result.length, (index) => Map<String, dynamic>.from(result[index]),
            growable: true
        );
    }
    

    and the return type of elements of the returned list is _InternalLinkedHashMap<String, dynamic>