forked from hamed-rezaee/dart_design_patterns_collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository_usage.dart
35 lines (23 loc) · 1 KB
/
repository_usage.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import 'repository.dart';
Future<void> main() async {
final BaseRepository<UserModel> repository = MockUserRepository();
final UserModel newUser =
UserModel(id: 1, name: 'John Doe', email: '[email protected]');
await repository.insert(newUser);
final UserModel? user = await repository.getById(1);
print('id: ${user?.id}, name: ${user?.name}, email:${user?.email}');
final UserModel updatedUser =
UserModel(id: 1, name: 'New Jane Doe', email: '[email protected]');
await repository.update(updatedUser);
final List<UserModel> users = await repository.getAll();
print('user count: ${users.length}');
for (final UserModel user in users) {
print('id: ${user.id}, name: ${user.name}, email:${user.email}');
}
await repository.delete(1);
final List<UserModel> usersAfterDelete = await repository.getAll();
print('user count: ${users.length}');
for (final UserModel user in usersAfterDelete) {
print('id: ${user.id}, name: ${user.name}, email:${user.email}');
}
}