saveList static method

Future<void> saveList(
  1. List<StaticStockRecord> newList
)

Save full list

Implementation

static Future<void> saveList(List<StaticStockRecord> newList) async {
  final prefs = await SharedPreferences.getInstance();

  final existingJson = prefs.getStringList(_key) ?? [];

  final existingList = existingJson
      .map((e) => StaticStockRecord.fromJson(jsonDecode(e)))
      .toList();

  // merge
  existingList.addAll(newList);

  final mergedJson = existingList
      .map((e) => jsonEncode(e.toJson()))
      .toList();

  await prefs.setStringList(_key, mergedJson);
}