Let's define a repository interface and then implement a version of that interface as an in-memory cache:
- In the repositories folder, create a new file called repository.dart and add the following interface:
import 'package:flutter/foundation.dart';
abstract class Repository {
Model create();
List<Model> getAll();
Model get(int id);
void update(Model item);
void delete(Model item);
void clear();
}
- We also need to define a temporary storage class called Model that can be used in any implementation of our repository interface. Since this model is strongly coupled to the repository concept, we can add it to the same file:
class Model {
final int id;
final Map data;
const Model({
@required this.id,
this.data = const {},
});
}
- The repository interface can be implemented in several ways, but for the sake of simplicity, we are just going to implement an in-memory cache. In the repositories folder, create a new file called...