mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 04:15:04 +03:00
70 lines
1.8 KiB
Plaintext
70 lines
1.8 KiB
Plaintext
---
|
|
id: initializing
|
|
title: 'Initializing'
|
|
slug: initializing
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs'
|
|
import TabItem from '@theme/TabItem'
|
|
|
|
## Flutter
|
|
|
|
For `supabase-flutter`, you will be using the static `initialize()` method on `Supabase` class.
|
|
|
|
### Flutter `initialize()`
|
|
|
|
```dart title=main.dart
|
|
Future<void> main() async {
|
|
await Supabase.initialize(url: 'https://xyzcompany.supabase.co', anonKey: 'public-anon-key');
|
|
runApp(MyApp());
|
|
}
|
|
```
|
|
|
|
### Access `SupabaseClient` instance
|
|
|
|
Once you initialize Supabase in your `main()` method, you can access the `SupabaseClient` instance from anywhere in your app.
|
|
|
|
```dart
|
|
final supabase = Supabase.instance.client;
|
|
```
|
|
|
|
### Call `initialize()` with custom headers
|
|
|
|
You can pass `headers` to initialize your Supabase client with customer headers.
|
|
Here is an example of passing a custom auth header to Supabase client.
|
|
```dart title=main.dart
|
|
Future<void> main() async {
|
|
await Supabase.initialize(
|
|
url: 'https://xyzcompany.supabase.co',
|
|
anonKey: 'public-anon-key',
|
|
headers: {
|
|
'Authorization': 'Bearer $accessToken',
|
|
},
|
|
);
|
|
runApp(const MyApp());
|
|
}
|
|
```
|
|
|
|
### Call `initialize()`multiple times
|
|
|
|
You can initialize Supabase multiple times in your app. When doing so, call `dispose()` each time before you initialize again.
|
|
|
|
```dart
|
|
Supabase.instance.dispose();
|
|
|
|
await Supabase.initialize(url: 'https://xyzcompany.supabase.co', anonKey: 'public-anon-key');
|
|
```
|
|
|
|
## Other Dart Projects
|
|
|
|
You can initialize a new Supabase client using the `SupabaseClient()` method.
|
|
|
|
The Supabase client is your entrypoint to the rest of the Supabase functionality
|
|
and is the easiest way to interact with everything we offer within the Supabase ecosystem.
|
|
|
|
### Dart `SupabaseClient()`
|
|
|
|
```dart
|
|
final supabase = SupabaseClient('https://xyzcompany.supabase.co', 'public-anon-key');
|
|
```
|