assocFirst property

Map<String, dynamic>? get assocFirst

Returns the first row as an associative array, or null if no rows exist.

This is convenient for queries that are expected to return a single row, such as SELECT queries with LIMIT 1 or aggregate functions.

Example:

var firstRow = result.assocFirst;
if (firstRow != null) {
  print('User found: ${firstRow['name']}');
} else {
  print('No user found');
}

Implementation

Map<String, dynamic>? get assocFirst {
  if (rows.isEmpty) {
    return null;
  }
  return rows.first.assoc();
}