Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

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 client = supabaseclient('supabaseurl', 'supabasekey');

  // select from table `countries` ordering by `name`
  final response = await client
      .from('countries')
      .select()
      .order('name', ascending: true)
      .execute();
}

realtime

import 'package:supabase/supabase.dart';

main() {
  final client = supabaseclient('supabaseurl', 'supabasekey');

  // set up a listener to listen to changes in `countries` table
  final subscription = await client
      .from('countries')
      .on(supabaseeventtypes.all, (payload) {
        // do something when there is an update
      })
      .subscribe();

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

realtime data as stream

to receive relatime 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 client = supabaseclient('supabaseurl', 'supabasekey');

  // set up a listener to listen to changes in `countries` table
  final subscription = await client
      .from('countries')
      .stream()
      .order('name')
      .limit(30)
      .execute()
      .listen(_handlecountriesstream);

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

authentication

import 'package:supabase/supabase.dart';

main() {
  final client = supabaseclient('supabaseurl', 'supabasekey');

  // sign up user with email and password
  final response = await client
      .auth
      .signup('email', 'password');
}

storage

import 'package:supabase/supabase.dart';

main() {
  final client = 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 client
      .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, which returns a gotruesessionresponse.

if the error attribute is null, the request was successful and the method returns data of type session.

// sign up user with email and password
final response = await client.auth.signup('email', 'password');

if (response.error != null) {
  // error
  print('error: ${response.error?.message}');
} else {
  // success
  final session = response.data;
}

sign in

use the signin method. it works similar to the signup method.

// sign in user with email and password
final response = await client.auth.signin(email: 'email', password: 'password');

if (response.error != null) {
  // error
  print('error: ${response.error?.message}');
} else {
  // success
  final session = response.data;
}

sign out

use the signout method, which returns a gotrueresponse.

also for the sign out check that error is null to know if the request was successful.

// sign out user
final response = await client.auth.signout();

if (response.error != null) {
  // error
  print('error: ${response.error?.message}');
} else {
  // success
}

check out the official documentation to learn all the other available methods.

guides

  • flutter supabase authentication – blog

contributing

  • download the repo on
  • download 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


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.