import 'package:get_storage/get_storage.dart'; import 'package:release_schedule/model/movie.dart'; class LocalMovieStorage { List _storedMovies = []; update(List movies) { _storedMovies = movies; } Future> retrieve() async { return _storedMovies; } } class LocalMovieStorageGetStorage extends LocalMovieStorage { Future? initialized; GetStorage? container; MovieData Function(Map jsonEncodable) toMovieData; LocalMovieStorageGetStorage(this.toMovieData) { initialized = _init(); } _init() async { await GetStorage.init("movies"); container = GetStorage("movies"); } @override update(List movies) async { await initialized; container!.write( "movies", movies.map((movie) => movie.toJsonEncodable()).toList()); } @override Future> retrieve() async { await initialized; dynamic movies = container!.read("movies"); if (movies == null) { return []; } return (movies as List) .map((encodable) => toMovieData(encodable)) .toList(); } }