fetch method Null safety

Future<List<T>> fetch(
  1. Bean<T> obj,
  2. {bool all = false,
  3. int limit = 0,
  4. int offset = 0,
  5. List<Column> orderBy = const []}
)

Implementation

Future<List<T>> fetch(Bean<T> obj,
    {bool all = false,
    int limit = 0,
    int offset = 0,
    List<Column> orderBy = const []}) async {
  List<Map<String, Map<String, dynamic>>> resultSet;
  if (!all) {
    if (limit > 0) {
      statement += ' LIMIT $limit';
    }
    if (offset > 0) {
      statement += ' OFFSET $offset';
    }
    if (orderBy.isNotEmpty) {
      statement +=
          ' ORDER BY ${orderBy.map((col) => col.orderField()).toList().join(' ')}';
    }
    final params = obj.asMap();
    resultSet =
        await ctx.mappedResultsQuery(statement, substitutionValues: params);
  } else {
    resultSet = await ctx.mappedResultsQuery(statement);
  }
  if (resultSet.isNotEmpty) {
    return resultSet
        .map((row) => obj.fromMap(row[tableInfo.tableName]!))
        .toList();
  } else {
    return <T>[];
  }
}