loadFilter static method

Future<Filter> loadFilter(
  1. int rangePhotosValuesEnd,
  2. DateTime endDate
)

Loads the filter settings from shared preferences. rangePhotosValuesEnd is the maximum number of photos taken in a day and endDate is the last available date in the data.

Implementation

static Future<Filter> loadFilter(
    int rangePhotosValuesEnd, DateTime endDate) async {
  // Getting an instance of SharedPreferences
  SharedPreferences prefs = await SharedPreferences.getInstance();

  return Filter(
    // Load the starting range of photo values or set the default value to 1
    rangePhotosValuesStart: prefs.getInt('rangePhotosValuesStart') ?? 1,

    // Load the ending range of photo values or set the default value to the maximum number of photos taken in a day
    rangePhotosValuesEnd:
        prefs.getInt('rangePhotosValuesEnd') ?? rangePhotosValuesEnd,

    // Load the start date or set it to the first available date in the data
    startDate: DateTime.parse(
        prefs.getString('startDate') ?? defaultDate.toIso8601String()),

    // Load the end date or set it to the last available date in the data
    endDate: DateTime.parse(
        prefs.getString('endDate') ?? endDate.toIso8601String()),

    // Load the list of selected cameras or set it to all cameras
    camerasSelected: prefs.getStringList('cameras') ?? cameras.keys.toList(),
  );
}