diff --git a/docs/offline_first/offline_first_with_supabase_repository.md b/docs/offline_first/offline_first_with_supabase_repository.md index bcb1399e..9177f721 100644 --- a/docs/offline_first/offline_first_with_supabase_repository.md +++ b/docs/offline_first/offline_first_with_supabase_repository.md @@ -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: ...) ``` diff --git a/example_supabase/lib/brick/repository.dart b/example_supabase/lib/brick/repository.dart index d039db73..fbc99e0f 100644 --- a/example_supabase/lib/brick/repository.dart +++ b/example_supabase/lib/brick/repository.dart @@ -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, @@ -18,28 +17,25 @@ class Repository extends OfflineFirstWithSupabaseRepository { super.memoryCacheProvider, }); - factory Repository() => _singleton!; + factory Repository() => _instance!; - static Future initializeSupabaseAndConfigure({ - required String supabaseUrl, - required String supabaseAnonKey, - }) async { + static Future 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', @@ -48,6 +44,7 @@ class Repository extends OfflineFirstWithSupabaseRepository { ), migrations: migrations, offlineRequestQueue: queue, + // Specify class types that should be cached in memory memoryCacheProvider: MemoryCacheProvider(), ); } diff --git a/packages/brick_offline_first_with_supabase/README.md b/packages/brick_offline_first_with_supabase/README.md index dc387aa1..296976e9 100644 --- a/packages/brick_offline_first_with_supabase/README.md +++ b/packages/brick_offline_first_with_supabase/README.md @@ -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: ...) ```