Overview of the postgrest package
mainpostgrest package is a Dart client library for PostgREST. It provides an ORM-like interface to interact with a Supabase database, allowing you to perform database operations through a structured Dart API.repository·main·Indexed 21 days ago
https://github.com/supabase/supabase-flutterThe official Flutter client library for interacting with Supabase services, including Postgrest, GoTrue, Realtime, and Storage. It provides tools for authentication (Email, OTP, OAuth, Anonymous, MFA, and Passkeys), database CRUD operations via PostgREST, and invoking Supabase Edge Functions.
postgrest package is a Dart client library for PostgREST. It provides an ORM-like interface to interact with a Supabase database, allowing you to perform database operations through a structured Dart API.supabase_typegen is a command-line code generator designed to transform a Supabase database schema into typed Dart table definitions. These definitions are intended for use with Supabase client packages to provide type safety when interacting with your database.
Note: As of the current version, this package is a placeholder on pub.dev to reserve the name. The actual code generator implementation is under development and is not yet functional.
realtime_client is a Dart client library for Supabase Realtime. It allows you to listen to changes in a PostgreSQL database over WebSockets, enabling real-time features in your Dart or Flutter applications.gotrue package is the official Dart client library for Supabase Auth. It provides the necessary functionality to manage user authentication within Dart and Flutter applications using the Supabase backend.The storage_client is a Dart client library designed to allow developers to interact with Supabase Storage. It provides the necessary methods to manage files, buckets, and other storage-related operations within a Dart or Flutter application.
For detailed API documentation and specific implementation guides, refer to the official Supabase documentation:
functions_client is a Dart client library designed to allow your Flutter or Dart applications to invoke and interact with Supabase Edge Functions. It provides the necessary plumbing to send requests to your deployed functions and handle responses within the Supabase ecosystem.Choosing between supabase and supabase_flutter depends on your target environment:
supabase if you are working in a non-Flutter Dart environment, such as server-side Dart (e.g., Dart Edge).supabase_flutter if you are developing a Flutter application.The supabase package is the core Dart client library designed for environments where Flutter's UI framework and plugin ecosystem are not present.
The authentication example demonstrates several sign-in methods available in supabase_flutter. The following patterns are used:
signUp, signInWithPassword, resetPasswordForEmail, and verifyOTP with OtpType.recovery followed by updateUser.signInWithOtp(email: ...) followed by verifyOTP(type: OtpType.email).signInWithOtp(phone: ...) followed by verifyOTP(type: OtpType.sms).signInWithOAuth for providers like Google, GitHub, and Apple. This requires configuring a redirectTo deep link (e.g., io.supabase.authexample://login-callback/) to return the user to the app.signInAnonymously, which can later be upgraded to a permanent account using updateUser to add an email and password.auth.mfa.enroll, challengeAndVerify, listFactors, and unenroll to manage TOTP factors.The realtime_room example demonstrates how to combine the three core pillars of Supabase Realtime within a single Flutter application channel:
INSERT or DELETE) on a specific table to keep local state in sync with the database without manual re-fetching. Use onPostgresChanges to subscribe to these events.sendBroadcastMessage to emit data and onBroadcast to listen for it.track to share local state, onPresenceSync to listen for changes in the room, and presenceState to view the current state of all participants.Realtime allows you to receive live updates from your database.
You can convert a database query into a Stream using .stream(primaryKey: [...]).
Warning: When using StreamBuilder in Flutter, persist the stream in a StatefulWidget variable rather than constructing it inside the build method to prevent rapid rebuilds and connection loss.
Listen to specific table changes (Insert, Update, Delete) using onPostgresChanges on a channel.
Send low-latency messages between clients without hitting the database using sendBroadcastMessage and onBroadcast.
// Realtime as a Stream
class _MyWidgetState extends State<MyWidget> {
final stream = supabase.from('countries').stream(primaryKey: ['id']);
@override
Widget build(BuildContext context) {
return StreamBuilder<List<Map<String, dynamic>>>(stream: stream, builder: (context, snapshot) {
// ...
});
}
}
// Postgres Changes
final myChannel = supabase.channel('my_channel');
myChannel
.onPostgresChanges(
event: PostgresChangeEvent.all,
schema: 'public',
table: 'countries',
callback: (payload) {
// Handle change
},
)
.subscribe();
// Broadcast
await myChannel.sendBroadcastMessage(
event: 'cursor-pos',
payload: {'x': 30, 'y': 50},
);To implement native Apple sign-in on iOS or macOS, use the sign_in_with_apple package alongside supabase_flutter.
sign_in_with_apple setup instructions for iOS/macOS.Authentication -> Providers -> Apple.signInWithIdToken with OAuthProvider.apple to complete the Supabase authentication.import 'package:sign_in_with_apple/sign_in_with_apple.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
/// Performs Apple sign in on iOS or macOS
Future<AuthResponse> signInWithApple() async {
final rawNonce = supabase.auth.generateRawNonce();
final hashedNonce = sha256.convert(utf8.encode(rawNonce)).toString();
final credential = await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
nonce: hashedNonce,
);
final idToken = credential.identityToken;
if (idToken == null) {
throw const AuthException(
'Could not find ID Token from generated credential.');
}
return signInWithIdToken(
provider: OAuthProvider.apple,
idToken: idToken,
nonce: rawNonce,
);
}You can run the passkey example locally using the provided launcher, or connect it to a specific Supabase project using --dart-define flags.
This boots a local Supabase stack and runs the example with pre-configured credentials.
cd examples
./run.shPass your project's URL and publishable key as --dart-defines.
flutter run -d chrome \
--dart-define=SUPABASE_URL=https://YOUR_PROJECT.supabase.co \
--dart-define=SUPABASE_PUBLISHABLE_KEY=YOUR_PUBLISHABLE_KEYNote: Passkeys are bound to the domain (relying party) they were created on. A passkey registered on localhost will not work on a different domain.