💻
Flutter documentation
  • Flutter documentation
    • Starting an App
    • Import
  • Visual Studio Code
  • Widgets
    • Stateless Widget
    • Stateful Widget
    • Scaffold
    • Text
      • OverFlow
      • Rounded background text
    • Padding
    • Align
    • DraggableScrollableSheet
    • Container
    • Decorated box
    • Expanded
    • IntrinsicHeight
    • IntrinsicWidth
    • ListView.builder(...)
    • Buttons
    • Gauge
    • Navigator
      • WillPopScope
    • Web View
    • Divider
    • Future builder
    • Image
      • Cached_network_image
      • Fade In Image
    • ClipOval
    • InkWell
    • Wrap
    • SingleChildScrollView
    • Stack
    • FittedBox
    • DropdownButton
    • ValueListenableBuilder
    • Maps
    • fl_chart
    • Set SystemNavigation Bar Color
    • Onesignal
    • Builder
    • Set orientation
    • SSE
    • Chat
    • Flutter_animate
    • Supabase
      • Android
    • Changing name and package name
    • Sign apk/abb
  • Dart
    • If / Else in one line
    • Functions
  • Others
  • Airtable
Powered by GitBook
On this page
  • SignUp a user
  • LogIn a user
  • Verify if the account is created
  • LogOut
  1. Widgets

Supabase

Supabase is a cloud-based platform for building scalable and secure backend applications.

First we have to start the supabase

Future<void> main() async {
  await Supabase.initialize(
    url: 'https://xyzcompany.supabase.co',
    anonKey: 'public-anon-key',
  );

  runApp(MyApp());
}

// Get a reference your Supabase client
final supabase = Supabase.instance.client;

SignUp a user

  // create email account
  Future<void> createAccountEmail(String email, String password,
      {Function(AuthException)? onError}) async {
    try {
      final response = await _supabaseClient.auth.signUp(
        email: email,
        password: password,
      );
      final session = response.session;
      final user = response.user;
    } on AuthException catch (error) {
      //error
      onError?.call(error);
    }

LogIn a user

  // login account with email
  Future<void> logInAccountEmail(String email, String password,
      {Function(AuthException)? onError, Function()? onDone}) async {
    try {
      final AuthResponse res = await supabase.auth.signInWithPassword(
        email: email,
        password: password,
      );
      final Session? session = res.session;
      final User? user = res.user;
      onDone?.call();
    } on AuthException catch (error) {
      // if there is an error with the log in, the function specified by the user can be executed
      onError?.call(error);
    }
  }

Verify if the account is created

void main() async {

  if (supabase.auth.currentSession == null) {
  // account not logged
    runApp(MyApp());
  } else {
  // acount logged 
    runApp(MyHomePage());
  }
}

LogOut

await supabase.auth.signOut();

https://supabase.com/docs/reference/dart/

PreviousFlutter_animateNextAndroid

Last updated 1 year ago