Initializing
Flutter#
For supabase-flutter
, you will be using the static initialize()
method on Supabase
class.
Flutter initialize()
#
main.dart1Future<void> main() async { 2 await Supabase.initialize(url: 'https://xyzcompany.supabase.co', anonKey: 'public-anon-key'); 3 runApp(MyApp()); 4}
Access SupabaseClient
instance#
Once you initialize Supabase in your main()
method, you can access the SupabaseClient
instance from anywhere in your app.
1final 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.
main.dart1Future<void> main() async { 2 await Supabase.initialize( 3 url: 'https://xyzcompany.supabase.co', 4 anonKey: 'public-anon-key', 5 headers: { 6 'Authorization': 'Bearer $accessToken', 7 }, 8 ); 9 runApp(const MyApp()); 10}
Call initialize()
multiple times#
You can initialize Supabase multiple times in your app. When doing so, call dispose()
each time before you initialize again.
1Supabase.instance.dispose(); 2 3await 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()
#
1final supabase = SupabaseClient('https://xyzcompany.supabase.co', 'public-anon-key');