-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathexample.dart
More file actions
85 lines (71 loc) · 2.05 KB
/
example.dart
File metadata and controls
85 lines (71 loc) · 2.05 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import 'package:brick_core/core.dart';
import 'package:brick_supabase/brick_supabase.dart';
import 'package:supabase/supabase.dart';
/// This class and code is always generated.
/// It is included here as an illustration.
/// Supabase adapters are generated by domains that utilize the brick_supabase_generators package,
/// such as brick_offline_first_with_supabase_build
class UserAdapter extends SupabaseAdapter<User> {
@override
final supabaseTableName = 'users';
@override
Future<User> fromSupabase(
Map<String, dynamic> data, {
required SupabaseProvider provider,
ModelRepository<SupabaseModel>? repository,
}) async {
return User(
name: data['name'],
);
}
@override
Future<Map<String, dynamic>> toSupabase(
User instance, {
required SupabaseProvider provider,
ModelRepository<SupabaseModel>? repository,
}) async {
return {
'name': instance.name,
};
}
@override
final defaultToNull = false;
@override
final fieldsToSupabaseColumns = {
'name': const RuntimeSupabaseColumnDefinition(columnName: 'name'),
};
@override
final ignoreDuplicates = false;
@override
final onConflict = null;
@override
final uniqueFields = {};
}
/// This value is always generated.
/// It is included here as an illustration.
/// Import it from `lib/brick/brick.g.dart` in your application.
final dictionary = SupabaseModelDictionary({
User: UserAdapter(),
});
/// A model is unique to the end implementation (e.g. a Flutter app)
class User extends SupabaseModel {
final String name;
User({
required this.name,
});
}
class MyRepository extends SingleProviderRepository<SupabaseModel> {
MyRepository(String apiUrl, String supabaseAnonKey)
: super(
SupabaseProvider(
SupabaseClient(apiUrl, supabaseAnonKey),
modelDictionary: dictionary,
),
);
}
void main() async {
final repository = MyRepository('http://localhost:8080', 'YOUR_API_KEY_HERE');
final users = await repository.get<User>();
// ignore: avoid_print
print(users);
}