SupabaseClient constructor
- String supabaseUrl,
- String supabaseKey, {
- PostgrestClientOptions postgrestOptions = const PostgrestClientOptions(),
- AuthClientOptions authOptions = const AuthClientOptions(),
- StorageClientOptions storageOptions = const StorageClientOptions(),
- RealtimeClientOptions realtimeClientOptions = const RealtimeClientOptions(),
- Map<
String, String> ? headers, - Client? httpClient,
- YAJsonIsolate? isolate,
Creates a Supabase client to interact with your Supabase instance.
supabaseUrl
and supabaseKey
can be found on your Supabase dashboard.
You can access none public schema by passing different schema.
Default headers can be overridden by specifying headers
.
Custom http client can be used by passing httpClient
parameter.
storageRetryAttempts
specifies how many retry attempts there should be to
upload a file to Supabase storage when failed due to network interruption.
realtimeClientOptions
specifies different options you can pass to RealtimeClient
.
Pass an instance of YAJsonIsolate
to isolate
to use your own persisted
isolate instance. A new instance will be created if isolate
is omitted.
Pass an instance of gotrueAsyncStorage
and set the authFlowType
to
AuthFlowType.pkce
in order to perform auth actions with pkce flow.
Implementation
SupabaseClient(
String supabaseUrl,
String supabaseKey, {
PostgrestClientOptions postgrestOptions = const PostgrestClientOptions(),
AuthClientOptions authOptions = const AuthClientOptions(),
StorageClientOptions storageOptions = const StorageClientOptions(),
RealtimeClientOptions realtimeClientOptions = const RealtimeClientOptions(),
Map<String, String>? headers,
Client? httpClient,
YAJsonIsolate? isolate,
}) : _supabaseKey = supabaseKey,
_restUrl = '$supabaseUrl/rest/v1',
_realtimeUrl = '$supabaseUrl/realtime/v1'.replaceAll('http', 'ws'),
_authUrl = '$supabaseUrl/auth/v1',
_storageUrl = '$supabaseUrl/storage/v1',
_functionsUrl = '$supabaseUrl/functions/v1',
_postgrestOptions = postgrestOptions,
_headers = {
...Constants.defaultHeaders,
if (headers != null) ...headers
},
_httpClient = httpClient,
_isolate = isolate ?? (YAJsonIsolate()..initialize()) {
auth = _initSupabaseAuthClient(
autoRefreshToken: authOptions.autoRefreshToken,
gotrueAsyncStorage: authOptions.pkceAsyncStorage,
authFlowType: authOptions.authFlowType,
);
_authHttpClient =
AuthHttpClient(_supabaseKey, httpClient ?? Client(), auth);
rest = _initRestClient();
functions = _initFunctionsClient();
storage = _initStorageClient(storageOptions.retryAttempts);
realtime = _initRealtimeClient(options: realtimeClientOptions);
_listenForAuthEvents();
}