supabase 1.0.1 copy "supabase: ^1.0.1" to clipboard
supabase: ^1.0.1 copied to clipboard

A dart client for Supabase. This client makes it simple for developers to build secure and scalable products.

supabase-dart #

A Dart client for Supabase.

pub package pub test


What is Supabase #

Supabase is an open source Firebase alternative. We are a service to:

  • listen to database changes
  • query your tables, including filtering, pagination, and deeply nested relationships (like GraphQL)
  • create, update, and delete rows
  • manage your users and their permissions
  • interact with your database using a simple UI

Status #

  • Alpha: Under heavy development
  • Public Alpha: Ready for testing. But go easy on us, there will be bugs and missing functionality.
  • Public Beta: Stable. No breaking changes expected in this version but possible bugs.
  • Public: Production-ready

Docs #

supabase-dart mirrors the design of supabase-js. Find the documentation here.

Usage example #

Database #

import 'package:supabase/supabase.dart';

main() {
  final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');

  // Select from table `countries` ordering by `name`
  final data = await supabase
      .from('countries')
      .select()
      .order('name', ascending: true);
}

Realtime #

import 'package:supabase/supabase.dart';

main() {
  final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');

  // Set up a listener to listen to changes in `countries` table
  supabase.channel('my_channel').on(RealtimeListenTypes.postgresChanges, ChannelFilter(
      event: '*',
      schema: 'public',
      table: 'countries'
    ), (payload, [ref]) {
      // Do something when there is an update
    }).subscribe();

  // remember to remove the channels when you're done
  supabase.removeAllChannels();
}

Realtime data as Stream #

To receive realtime updates, you have to first enable Realtime on from your Supabase console. You can read more here on how to enable it.

import 'package:supabase/supabase.dart';

main() {
  final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');

  // Set up a listener to listen to changes in `countries` table
  final subscription = supabase
      .from('countries')
      .stream(primaryKey: ['id']) // Pass list of primary key column names
      .order('name')
      .limit(30)
      .listen(_handleCountriesStream);

  // remember to remove subscription when you're done
  subscription.cancel();
}

Authentication #

import 'package:supabase/supabase.dart';

main() {
  final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');

  // Sign up user with email and password
  final response = await supabase
    .auth
    .signUp(email: '[email protected]', password: 'password');
}

Storage #

import 'package:supabase/supabase.dart';

main() {
  final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');

  // Create file `example.txt` and upload it in `public` bucket
  final file = File('example.txt');
  file.writeAsStringSync('File content');
  final storageResponse = await supabase
      .storage
      .from('public')
      .upload('example.txt', file);
}

Authentication #

Initialize a SupabaseClient by passing your Supabase URL and Supabase KEY. The keys can be found in your supabase project in /setting/API.

final client = SupabaseClient('supabaseUrl', 'supabaseKey');

The client has a auth attribute (of type GoTrueClient) that you can use to authenticate your users using supabase.

Sign up #

Use the signUp method to create a new user account.

// Sign up user with email and password
final response = await supabase.auth.signUp(email: email, password: password);
final Session? session = response.session;
final User? user = response.user;

Sign in #

There are a few ways to sign in a user into your app.

Use the signInWithPassword method to sign in a user with their email or phone with password.

// Sign in user with email and password
final response = await client.auth.signInWithPassword(email: email, password: password);
final Session? session = response.session;
final User? user = response.user;

Use the signInWithOtp method to sign in a user using magic link with email or one time password using phone number.

// Sign in user with email and password
await client.auth.signInWithOtp(email: email);

Sign out #

Use the signOut method to sign out a user.

// Sign out user
await client.auth.signOut();

Check out the Official Documentation to learn all the other available methods.

Guides #

  • Flutter Supabase Authentication - Blog

Contributing #

  • Fork the repo on GitHub
  • Clone the project to your own machine
  • Commit changes to your own branch
  • Push your work back up to your fork
  • Submit a Pull request so that we can review your changes and merge

License #

This repo is licenced under MIT.

Credits #

505
likes
0
pub points
98%
popularity

Publisher

verified publishersupabase.io

A dart client for Supabase. This client makes it simple for developers to build secure and scalable products.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

functions_client, gotrue, http, postgrest, realtime_client, storage_client

More

Packages that depend on supabase