getLocations static method

Future<List<LocationData>> getLocations({
  1. int? limit,
})

Get stored locations from database

Implementation

static Future<List<LocationData>> getLocations({int? limit}) async {
  try {
    if (_database == null) await _initDatabase();

    final List<Map<String, dynamic>> maps = await _database!.query(
      'locations',
      orderBy: 'timestamp DESC',
      limit: limit,
    );

    return List.generate(maps.length, (i) {
      return LocationData.fromMap(maps[i]);
    });
  } catch (e) {
    print('Error getting locations: $e');
    return [];
  }
}