2 Star 0 Fork 0

memfiredb / supabase-dart

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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

  • 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

MIT License Copyright (c) 2020 Supabase Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
Dart
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/memfiredb/supabase-dart.git
git@gitee.com:memfiredb/supabase-dart.git
memfiredb
supabase-dart
supabase-dart
main

搜索帮助