Flutter Client Library
supabase_flutterView on GitHubThis reference documents every object and method available in Supabase's Flutter library, supabase-flutter. You can use supabase-flutter to interact with your Postgres database, listen to database changes, invoke Deno Edge Functions, build login and user management functionality, and manage large files.
We also provide a supabase package for non-Flutter projects.
Installing
Install from pub.dev
You can install the Supabase package from pub.dev.
Initializing
You can initialize Supabase with the static initialize()
method of Supabase
class.
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.
_11Future<void> main() async {_11 await Supabase.initialize(_11 url: 'https://xyzcompany.supabase.co',_11 anonKey: 'public-anon-key',_11 );_11_11 runApp(MyApp());_11}_11_11// Get a reference your Supabase client_11final supabase = Supabase.instance.client;
Fetch data
Perform a SELECT query on the table or view.
- By default, Supabase projects will return a maximum of 1,000 rows. This setting can be changed in Project API Settings. It's recommended that you keep it low to limit the payload size of accidental or malicious requests. You can use
range()
queries to paginate through your data. select()
can be combined with Filtersselect()
can be combined with Modifiersapikey
is a reserved keyword if you're using the Supabase Platform and should be avoided as a column name.
_10final data = await supabase_10 .from('cities')_10 .select('name');
Insert data
Perform an INSERT into the table or view.
_10await supabase_10 .from('cities')_10 .insert({'name': 'The Shire', 'country_id': 554});
Update data
Perform an UPDATE on the table or view.
update()
should always be combined with Filters to target the item(s) you wish to update.
_10await supabase_10 .from('cities')_10 .update({ 'name': 'Middle Earth' })_10 .match({ 'name': 'Auckland' });
Upsert data
Perform an UPSERT on the table or view. Depending on the column(s) passed to onConflict
, .upsert()
allows you to perform the equivalent of .insert()
if a row with the corresponding onConflict
columns doesn't exist, or if it does exist, perform an alternative action depending on ignoreDuplicates
.
- Primary keys must be included in
values
to use upsert.
_10await supabase_10 .from('messages')_10 .upsert({ 'id': 3, 'message': 'foo', 'username': 'supabot' });
Delete data
Perform a DELETE on the table or view.
delete()
should always be combined with Filters to target the item(s) you wish to delete.- If you use
delete()
with filters and you have RLS enabled, only rows visible throughSELECT
policies are deleted. Note that by default no rows are visible, so you need at least oneSELECT
/ALL
policy that makes the rows visible.
_10await supabase_10 .from('cities')_10 .delete()_10 .match({ 'id': 666 });
Call a Postgres function
You can call stored procedures as a "Remote Procedure Call".
That's a fancy way of saying that you can put some logic into your database then call it from anywhere. It's especially useful when the logic rarely changes - like password resets and updates.
_10final data = await supabase_10 .rpc('hello_world');
Using filters
Filters allow you to only return rows that match certain conditions.
Filters can be used on select()
, update()
, and delete()
queries.
If a Database function returns a table response, you can also apply filters.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .eq('name', 'The Shire'); // Correct_10_10final data = await supabase_10 .from('cities')_10 .eq('name', 'The Shire') // Incorrect_10 .select('name, country_id');
Column is equal to a value
Finds all rows whose value on the stated column
exactly matches the specified value
.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .eq('name', 'The shire');
Column is not equal to a value
Finds all rows whose value on the stated column
doesn't match the specified value
.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .neq('name', 'The shire');
Column is greater than a value
Finds all rows whose value on the stated column
is greater than the specified value
.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .gt('country_id', 250);
Column is greater than or equal to a value
Finds all rows whose value on the stated column
is greater than or equal to the specified value
.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .gte('country_id', 250);
Column is less than a value
Finds all rows whose value on the stated column
is less than the specified value
.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .lt('country_id', 250);
Column is less than or equal to a value
Finds all rows whose value on the stated column
is less than or equal to the specified value
.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .lte('country_id', 250);
Column matches a pattern
Finds all rows whose value in the stated column
matches the supplied pattern
(case sensitive).
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .like('name', '%la%');
Column matches a case-insensitive pattern
Finds all rows whose value in the stated column
matches the supplied pattern
(case insensitive).
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .ilike('name', '%la%');
Column is a value
A check for exact equality (null, true, false), finds all rows whose value on the stated column
exactly match the specified value
.
is_
and in_
filter methods are suffixed with _
to avoid collisions with reserved keywords.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .is_('name', null);
Column is in an array
Finds all rows whose value on the stated column
is found on the specified values
.
is_
and in_
filter methods are suffixed with _
to avoid collisions with reserved keywords.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .in_('name', ['Rio de Janeiro', 'San Francisco']);
Column contains every element in a value
_10final data = await supabase_10 .from('countries')_10 .select('name, id, main_exports')_10 .contains('main_exports', ['oil']);
Contained by value
_10final data = await supabase_10 .from('countries')_10 .select('name, id, main_exports')_10 .containedBy('main_exports', ['cars', 'food', 'machine']);
Greater than a range
_10final data = await supabase_10 .from('countries')_10 .select('name, id, population_range_millions')_10 .rangeGt('population_range_millions', '[150, 250]');
Greater than or equal to a range
_10final data = await supabase_10 .from('countries')_10 .select('name, id, population_range_millions')_10 .rangeGte('population_range_millions', '[150, 250]');
Less than a range
_10final data = await supabase_10 .from('countries')_10 .select('name, id, population_range_millions')_10 .rangeLt('population_range_millions', '[150, 250]');
Less than or equal to a range
_10final data = await supabase_10 .from('countries')_10 .select('name, id, population_range_millions')_10 .rangeLte('population_range_millions', '[150, 250]');
Mutually exclusive to a range
_10final data = await supabase_10 .from('countries')_10 .select('name, id, population_range_millions')_10 .rangeAdjacent('population_range_millions', '[70, 185]');
With a common element
_10final data = await supabase_10 .from('countries')_10 .select('name, id, main_exports')_10 .overlaps('main_exports', ['computers', 'minerals']);
Match a string
Finds all rows whose tsvector value on the stated column
matches to_tsquery(query).
_10final data = await supabase_10 .from('quotes')_10 .select('catchphrase')_10 .textSearch('catchphrase', "'fat' & 'cat'",_10 config: 'english'_10 );
Match an associated value
Finds all rows whose columns match the specified query
object.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .match({'name': 'Beijing', 'country_id': 156});
Don't match the filter
Finds all rows which doesn't satisfy the filter.
-
.not()
expects you to use the raw PostgREST syntax for the filter names and values._10.not('name','eq','Paris')_10.not('arraycol','cs','{"a","b"}') // Use Postgres array {} for array column and 'cs' for contains._10.not('rangecol','cs','(1,2]') // Use Postgres range syntax for range column._10.not('id','in','(6,7)') // Use Postgres list () and 'in' for in_ filter._10.not('id','in','(${mylist.join(',')})') // You can insert a Dart list array.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .not('name', 'eq', 'Paris');
Match at least one filter
Finds all rows satisfying at least one of the filters.
-
.or()
expects you to use the raw PostgREST syntax for the filter names and values._10.or('id.in.(6,7),arraycol.cs.{"a","b"}') // Use Postgres list () and 'in' for in_ filter. Array {} and 'cs' for contains._10.or('id.in.(${mylist.join(',')}),arraycol.cs.{${mylistArray.join(',')}}') // You can insert a Dart list for list or array column._10.or('id.in.(${mylist.join(',')}),rangecol.cs.(${mylistRange.join(',')}]') // You can insert a Dart list for list or range column.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .or('id.eq.20,id.eq.30');
Match the filter
Finds all rows whose column
satisfies the filter.
.filter()
expects you to use the raw PostgREST syntax for the filter names and values, so it should only be used as an escape hatch in case other filters don't work._10.filter('arraycol','cs','{"a","b"}') // Use Postgres array {} and 'cs' for contains._10.filter('rangecol','cs','(1,2]') // Use Postgres range syntax for range column._10.filter('id','in','(6,7)') // Use Postgres list () and 'in' for in_ filter._10.filter('id','cs','{${mylist.join(',')}}') // You can insert a Dart array list.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .filter('name', 'in', '("Paris","Tokyo")');
Using modifiers
Filters work on the row level—they allow you to return rows that only match certain conditions without changing the shape of the rows. Modifiers are everything that don't fit that definition—allowing you to change the format of the response (e.g., returning a CSV string).
Modifiers must be specified after filters. Some modifiers only apply for queries that return rows (e.g., select()
or rpc()
on a function that returns a table response).
Order the results
Orders the result with the specified column.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .order('id', ascending: true);
Limit the number of rows returned
Limits the result with the specified count.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .limit(1);
Limit the query to a range
Limits the result to rows within the specified range, inclusive.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .range(0,3);
Retrieve one row of data
Retrieves only one row from the result. Result must be one row (e.g. using limit), otherwise this will result in an error.
_10final data = await supabase_10 .from('cities')_10 .select('name, country_id')_10 .single();
Create a new user
Creates a new user.
- By default, the user needs to verify their email address before logging in. To turn this off, disable Confirm email in your project.
- Confirm email determines if users need to confirm their email address after signing up.
- If Confirm email is enabled, a
user
is returned butsession
is null. - If Confirm email is disabled, both a
user
and asession
are returned.
- If Confirm email is enabled, a
- When the user confirms their email address, they are redirected to the
SITE_URL
by default. You can modify yourSITE_URL
or add additional redirect URLs in your project. - If signUp() is called for an existing confirmed user:
- If Confirm email is enabled in your project, an obfuscated/fake user object is returned.
- If Confirm email is disabled, the error message,
User already registered
is returned.
_10final AuthResponse res = await supabase.auth.signUp(_10 email: 'example@email.com',_10 password: 'example-password',_10);_10final Session? session = res.session;_10final User? user = res.user;
Listen to auth events
Receive a notification every time an auth event happens.
- Types of auth events:
AuthChangeEvent.passwordRecovery
,AuthChangeEvent.signedIn
,AuthChangeEvent.signedOut
,AuthChangeEvent.tokenRefreshed
,AuthChangeEvent.userUpdated
andAuthChangeEvent.userDeleted
_10final authSubscription = supabase.auth.onAuthStateChange.listen((data) {_10 final AuthChangeEvent event = data.event;_10 final Session? session = data.session;_10});
Sign in a user
Log in an existing user using email or phone number with password.
- Requires either an email and password or a phone number and password.
_10final AuthResponse res = await supabase.auth.signInWithPassword(_10 email: 'example@email.com',_10 password: 'example-password',_10);_10final Session? session = res.session;_10final User? user = res.user;
Sign in a user through OTP
- Requires either an email or phone number.
- This method is used for passwordless sign-ins where a OTP is sent to the user's email or phone number.
- If you're using an email, you can configure whether you want the user to receive a magiclink or a OTP.
- If you're using phone, you can configure whether you want the user to receive a OTP.
- The magic link's destination URL is determined by the
SITE_URL
. You can modify theSITE_URL
or add additional redirect urls in your project.
_10await supabase.auth.signInWithOtp(_10 email: 'example@email.com',_10 emailRedirectTo: kIsWeb ? null : 'io.supabase.flutter://signin-callback/',_10);
Sign in with Apple
Signs in a user using native Apple login.
- You need to register your bundle ID and add it to Supabase dashboard.
- This method is only available in iOS and macOS
- For other platforms, signInWithOAuth() should be used.
_10final AuthResponse res = await supabase.auth.signInWithApple();
Sign in a user through OAuth
Signs the user in using third party OAuth providers.
- This method is used for signing in using a third-party provider.
- Supabase supports many different third-party providers.
_10await supabase.auth.signInWithOAuth(Provider.github);
Sign out a user
Signs out the current user, if there is a logged in user.
- In order to use the
signOut()
method, the user needs to be signed in first.
_10await supabase.auth.signOut();
Verify and log in through OTP
- The
verifyOtp
method takes in different verification types. If a phone number is used, the type can either besms
orphone_change
. If an email address is used, the type can be one of the following:signup
,magiclink
,recovery
,invite
oremail_change
. - The verification type used should be determined based on the corresponding auth method called before
verifyOtp
to sign up / sign-in a user.
_10final AuthResponse res = await supabase.auth.verifyOTP(_10 type: OtpType.sms,_10 token: '111111',_10 phone: '+13334445555',_10);_10final Session? session = res.session;_10final User? user = res.user;
Retrieve a session
Returns the session data, if there is an active session.
_10final Session? session = supabase.auth.currentSession;
Retrieve a user
Returns the user data, if there is a logged in user.
_10final User? user = supabase.auth.currentUser;
Update a user
Updates user data for a logged in user.
- In order to use the
updateUser()
method, the user needs to be signed in first. - By Default, email updates sends a confirmation link to both the user's current and new email. To only send a confirmation link to the user's new email, disable Secure email change in your project's email auth provider settings.
_10final UserResponse res = await supabase.auth.updateUser(_10 UserAttributes(_10 email: 'example@email.com',_10 ),_10);_10final User? updatedUser = res.user;
Send a password reauthentication nonce
- This method is used together with
updateUser()
when a user's password needs to be updated. - This method will send a nonce to the user's email. If the user doesn't have a confirmed email address, the method will send the nonce to the user's confirmed phone number instead.
_10await supabase.auth.reauthenticate();
Resend an OTP
- Resends a signup confirmation, email change or phone change email to the user.
- Passwordless sign-ins can be resent by calling the
signInWithOtp()
method again. - Password recovery emails can be resent by calling the
resetPasswordForEmail()
method again. - This method will only resend an email or phone OTP to the user if there was an initial signup, email change or phone change request being made.
_10final ResendResponse res = await supabase.auth.resend(_10 type: OtpType.email,_10 email: 'email@example.com',_10);
Auth MFA
This section contains methods commonly used for Multi-Factor Authentication (MFA) and are invoked behind the supabase.auth.mfa
namespace.
Currently, we only support time-based one-time password (TOTP) as the 2nd factor. We don't support recovery codes but we allow users to enroll more than 1 TOTP factor, with an upper limit of 10.
Having a 2nd TOTP factor for recovery frees the user of the burden of having to store their recovery codes somewhere. It also reduces the attack surface since multiple recovery codes are usually generated compared to just having 1 backup TOTP factor.
Enroll a factor
Starts the enrollment process for a new Multi-Factor Authentication (MFA) factor. This method creates a new unverified
factor. To verify a factor, present the QR code or secret to the user and ask them to add it to their authenticator app. The user has to enter the code from their authenticator app to verify it.
- Currently,
totp
is the only supportedfactorType
. The returnedid
should be used to create a challenge. - To create a challenge, see
mfa.challenge()
. - To verify a challenge, see
mfa.verify()
. - To create and verify a challenge in a single step, see
mfa.challengeAndVerify()
.
_10final res = await supabase.auth.mfa.enroll(factorType: FactorType.totp);_10_10final qrCodeUrl = res.totp.qrCode;
Create a challenge
Prepares a challenge used to verify that a user has access to a MFA factor.
- An enrolled factor is required before creating a challenge.
- To verify a challenge, see
mfa.verify()
.
_10final res = await supabase.auth.mfa.challenge(_10 factorId: '34e770dd-9ff9-416c-87fa-43b31d7ef225',_10);
Verify a challenge
Verifies a code against a challenge. The verification code is provided by the user by entering a code seen in their authenticator app.
- To verify a challenge, please create a challenge first.
_10final res = await supabase.auth.mfa.verify(_10 factorId: '34e770dd-9ff9-416c-87fa-43b31d7ef225',_10 challengeId: '4034ae6f-a8ce-4fb5-8ee5-69a5863a7c15',_10 code: '123456',_10);
Create and verify a challenge
Helper method which creates a challenge and immediately uses the given code to verify against it thereafter. The verification code is provided by the user by entering a code seen in their authenticator app.
- An enrolled factor is required before invoking
challengeAndVerify()
. - Executes
mfa.challenge()
andmfa.verify()
in a single step.
_10final res = await supabase.auth.mfa.challengeAndVerify(_10 factorId: '34e770dd-9ff9-416c-87fa-43b31d7ef225',_10 code: '123456',_10);
Unenroll a factor
Unenroll removes a MFA factor. A user has to have an aal2 authenticator level in order to unenroll a verified factor.
_10final res = await supabase.auth.mfa.unenroll(_10 '34e770dd-9ff9-416c-87fa-43b31d7ef225',_10);
Get Authenticator Assurance Level
Returns the Authenticator Assurance Level (AAL) for the active session.
- Authenticator Assurance Level (AAL) is the measure of the strength of an authentication mechanism.
- In Supabase, having an AAL of
aal1
refers to having the 1st factor of authentication such as an email and password or OAuth sign-in whileaal2
refers to the 2nd factor of authentication such as a time-based, one-time-password (TOTP). - If the user has a verified factor, the
nextLevel
field will returnaal2
, else, it will returnaal1
.
_10final res = supabase.auth.mfa.getAuthenticatorAssuranceLevel();_10final currentLevel = res.currentLevel;_10final nextLevel = res.nextLevel;_10final currentAuthenticationMethods = res.currentAuthenticationMethods;
Auth Admin
- Any method under the
supabase.auth.admin
namespace requires aservice_role
key. - These methods are considered admin methods and should be called on a trusted server. Never expose your
service_role
key in the Flutter app.
_10final supabase = SupabaseClient(supabaseUrl, serviceRoleKey);
Retrieve a user
Get user by id.
- Fetches the user object from the database based on the user's id.
- The
getUserById()
method requires the user's id which maps to theauth.users.id
column.
_10final res = await supabase.auth.admin.getUserById(userId);_10final user = res.user;
List all users
Get a list of users.
- Defaults to return 50 users per page.
_10final List<User> users = await supabase.auth.admin.listUsers();
Create a user
Creates a new user.
- To confirm the user's email address or phone number, set
email_confirm
orphone_confirm
to true. Both arguments default to false. createUser()
will not send a confirmation email to the user. You can useinviteUserByEmail()
if you want to send them an email invite instead.- If you are sure that the created user's email or phone number is legitimate and verified, you can set the
email_confirm
orphone_confirm
param totrue
.
_10final res = await supabase.auth.admin.createUser(AdminUserAttributes(_10 email: 'user@email.com',_10 password: 'password',_10 userMetadata: {'name': 'Yoda'},_10));
Delete a user
Delete a user.
- The
deleteUser()
method requires the user's ID, which maps to theauth.users.id
column.
_10await supabase.auth.admin_10 .deleteUser('715ed5db-f090-4b8c-a067-640ecee36aa0');
Send an email invite link
Sends an invite link to the user's email address.
_10final UserResponse res = await supabase.auth.admin_10 .inviteUserByEmail('email@example.com');_10final User? user = res.user;
Generate an email link
Generates email links and OTPs to be sent via a custom email provider.
- The following types can be passed into
generateLink()
:signup
,magiclink
,invite
,recovery
,emailChangeCurrent
,emailChangeNew
,phoneChange
. generateLink()
only generates the email link foremail_change_email
if the "Secure email change" setting is enabled under the "Email" provider in your Supabase project.generateLink()
handles the creation of the user forsignup
,invite
andmagiclink
.
_10final res = await supabase.auth.admin.generateLink(_10 type: GenerateLinkType.signup,_10 email: 'email@example.com',_10 password: 'secret',_10);_10final actionLink = res.properties.actionLink;
Update a user
_10final UserResponse res = await supabase.auth.admin.updateUserById(_10 '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4',_10 attributes: AdminUserAttributes(_10 email: 'new@email.com',_10 ),_10);
Invokes a Supabase Edge Function.
_10final res = await supabase.functions.invoke('hello', body: {'foo': 'baa'});_10final data = res.data;
Listen to database changes
Returns real-time data from your table as a Stream
.
- Realtime is disabled by default for new tables. You can turn it on by managing replication.
stream()
will emit the initial data as well as any further change on the database asStream<List<Map<String, dynamic>>>
by combining Postgrest and Realtime.- Takes a list of primary key column names that will be used to update and delete the proper records within the SDK.
- The following filters are available
.eq('column', value)
listens to rows where the column equals the value.neq('column', value)
listens to rows where the column does not equal the value.gt('column', value)
listens to rows where the column is greater than the value.gte('column', value)
listens to rows where the column is greater than or equal to the value.lt('column', value)
listens to rows where the column is less than the value.lte('column', value)
listens to rows where the column is less than or equal to the value.inFilter('column', [val1, val2, val3])
listens to rows where the column is one of the values
_10supabase.from('countries')_10 .stream(primaryKey: ['id'])_10 .listen((List<Map<String, dynamic>> data) {_10 // Do something awesome with the data_10});
Subscribe to channel
Subscribe to realtime changes in your database.
- Realtime is disabled by default for new tables. You can turn it on by managing replication.
- If you want to receive the "previous" data for updates and deletes, you will need to set
REPLICA IDENTITY
toFULL
, like this:ALTER TABLE your_table REPLICA IDENTITY FULL;
_10supabase.channel('*').on(_10 RealtimeListenTypes.postgresChanges,_10 ChannelFilter(event: '*', schema: '*'),_10 (payload, [ref]) {_10 print('Change received: ${payload.toString()}');_10 },_10).subscribe();
Unsubscribe from a channel
Unsubscribes and removes Realtime channel from Realtime client.
- Removing a channel is a great way to maintain the performance of your project's Realtime service as well as your database if you're listening to Postgres changes. Supabase will automatically handle cleanup 30 seconds after a client is disconnected, but unused channels may cause degradation as more clients are simultaneously subscribed.
_10final status = await supabase.removeChannel(channel);
Unsubscribe from all channels
Unsubscribes and removes all Realtime channels from Realtime client.
- Removing channels is a great way to maintain the performance of your project's Realtime service as well as your database if you're listening to Postgres changes. Supabase will automatically handle cleanup 30 seconds after a client is disconnected, but unused channels may cause degradation as more clients are simultaneously subscribed.
_10final statuses = await supabase.removeAllChannels();
Retrieve all channels
Returns all Realtime channels.
_10final channels = supabase.getChannels();
Create a bucket
Creates a new Storage bucket
- Policy permissions required:
buckets
permissions:insert
objects
permissions: none
_10final String bucketId = await supabase_10 .storage_10 .createBucket('avatars');
Retrieve a bucket
Retrieves the details of an existing Storage bucket.
- Policy permissions required:
buckets
permissions:select
objects
permissions: none
_10final Bucket bucket = await supabase_10 .storage_10 .getBucket('avatars');
List all buckets
Retrieves the details of all Storage buckets within an existing product.
- Policy permissions required:
buckets
permissions:select
objects
permissions: none
_10final List<Bucket> buckets = await supabase_10 .storage_10 .listBuckets();
Update a bucket
Updates a new Storage bucket
- Policy permissions required:
buckets
permissions:update
objects
permissions: none
_10final res = await supabase_10 .storage_10 .updateBucket('avatars', const BucketOptions(public: false));
Delete a bucket
Deletes an existing bucket. A bucket can't be deleted with existing objects inside it. You must first empty()
the bucket.
- Policy permissions required:
buckets
permissions:select
anddelete
objects
permissions: none
_10final String result = await supabase_10 .storage_10 .deleteBucket('avatars');
Empty a bucket
Removes all objects inside a single bucket.
- Policy permissions required:
buckets
permissions:select
objects
permissions:select
anddelete
_10final String result = await supabase_10 .storage_10 .emptyBucket('avatars');
Upload a file
Uploads a file to an existing bucket.
- Policy permissions required:
buckets
permissions: noneobjects
permissions:insert
_10final avatarFile = File('path/to/file');_10final String path = await supabase.storage.from('avatars').upload(_10 'public/avatar1.png',_10 avatarFile,_10 fileOptions: const FileOptions(cacheControl: '3600', upsert: false),_10 );
Download a file
Downloads a file.
- Policy permissions required:
buckets
permissions: noneobjects
permissions:select
_10final Uint8List file = await supabase_10 .storage_10 .from('avatars')_10 .download('avatar1.png');
List all files in a bucket
Lists all the files within a bucket.
- Policy permissions required:
buckets
permissions: noneobjects
permissions:select
_10final List<FileObject> objects = await supabase_10 .storage_10 .from('avatars')_10 .list();
Replace an existing file
Replaces an existing file at the specified path with a new one.
- Policy permissions required:
buckets
permissions: noneobjects
permissions:update
andselect
_10final avatarFile = File('path/to/local/file');_10final String path = await supabase.storage.from('avatars').update(_10 'public/avatar1.png',_10 avatarFile,_10 fileOptions: const FileOptions(cacheControl: '3600', upsert: false),_10 );
Move an existing file
Moves an existing file, optionally renaming it at the same time.
- Policy permissions required:
buckets
permissions: noneobjects
permissions:update
andselect
_10final String result = await supabase_10 .storage_10 .from('avatars')_10 .move('public/avatar1.png', 'private/avatar2.png');
Delete files in a bucket
Deletes files within the same bucket
- Policy permissions required:
buckets
permissions: noneobjects
permissions:delete
andselect
_10final List<FileObject> objects = await supabase_10 .storage_10 .from('avatars')_10 .remove(['avatar1.png']);
Create a signed URL
Create signed url to download file without requiring permissions. This URL can be valid for a set number of seconds.
- Policy permissions required:
buckets
permissions: noneobjects
permissions:select
_10final String signedUrl = await supabase_10 .storage_10 .from('avatars')_10 .createSignedUrl('avatar1.png', 60);
Retrieve public URL
Retrieve URLs for assets in public buckets
- The bucket needs to be set to public, either via updateBucket() or by going to Storage on supabase.com/dashboard, clicking the overflow menu on a bucket and choosing "Make public"
- Policy permissions required:
buckets
permissions: noneobjects
permissions: none
_10final String publicUrl = supabase_10 .storage_10 .from('public-bucket')_10 .getPublicUrl('avatar1.png');