Skip to content

Commit

Permalink
add url and anon
Browse files Browse the repository at this point in the history
  • Loading branch information
tshedor committed Oct 7, 2024
1 parent cf706e0 commit 071e351
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ When using [supabase_flutter](https://pub.dev/packages/supabase_flutter), create

```dart
final (client, queue) = OfflineFirstWithSupabaseRepository.clientQueue(databaseFactory: databaseFactory);
await Supabase.initialize(httpClient: client)
await Supabase.initialize(url: supabaseUrl, anonKey: supabaseAnonKey, httpClient: client)
final supabaseProvider = SupabaseProvider(Supabase.instance.client, modelDictionary: ...)
```

Expand Down
23 changes: 10 additions & 13 deletions example_supabase/lib/brick/repository.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Saved in my_app/lib/src/brick/repository.dart
import 'package:brick_offline_first_with_supabase/brick_offline_first_with_supabase.dart';
import 'package:brick_sqlite/brick_sqlite.dart';
import 'package:brick_sqlite/memory_cache_provider.dart';
import 'package:brick_supabase/brick_supabase.dart' hide Supabase;
import 'package:brick_supabase/brick_supabase.dart';
import 'package:pizza_shoppe/brick/brick.g.dart';
import 'package:pizza_shoppe/brick/db/schema.g.dart';
import 'package:sqflite/sqflite.dart' show databaseFactory;
import 'package:sqflite_common/sqlite_api.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

class Repository extends OfflineFirstWithSupabaseRepository {
static late Repository? _singleton;
static late Repository? _instance;

Repository._({
required super.supabaseProvider,
Expand All @@ -18,28 +17,25 @@ class Repository extends OfflineFirstWithSupabaseRepository {
super.memoryCacheProvider,
});

factory Repository() => _singleton!;
factory Repository() => _instance!;

static Future<void> initializeSupabaseAndConfigure({
required String supabaseUrl,
required String supabaseAnonKey,
}) async {
static Future<void> configure(DatabaseFactory databaseFactory) async {
final (client, queue) = OfflineFirstWithSupabaseRepository.clientQueue(
databaseFactory: databaseFactory,
);

final supabase = await Supabase.initialize(
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseAnonKey,
httpClient: client,
);

final provider = SupabaseProvider(
supabase.client,
Supabase.instance.client,
modelDictionary: supabaseModelDictionary,
);

_singleton = Repository._(
_instance = Repository._(
supabaseProvider: provider,
sqliteProvider: SqliteProvider(
'my_repository.sqlite',
Expand All @@ -48,6 +44,7 @@ class Repository extends OfflineFirstWithSupabaseRepository {
),
migrations: migrations,
offlineRequestQueue: queue,
// Specify class types that should be cached in memory
memoryCacheProvider: MemoryCacheProvider(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_offline_first_with_supabase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ When using [supabase_flutter](https://pub.dev/packages/supabase_flutter), create

```dart
final (client, queue) = OfflineFirstWithSupabaseRepository.clientQueue(databaseFactory: databaseFactory);
await Supabase.initialize(httpClient: client)
await Supabase.initialize(url: supabaseUrl, anonKey: supabaseAnonKey, httpClient: client)
final supabaseProvider = SupabaseProvider(Supabase.instance.client, modelDictionary: ...)
```

Expand Down

0 comments on commit 071e351

Please sign in to comment.