All Projects → adityathakurxd → supabase_flutter

adityathakurxd / supabase_flutter

Licence: other
Using Supabase in Flutter

Programming Languages

dart
5743 projects
HTML
75241 projects
swift
15916 projects
kotlin
9241 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to supabase flutter

Annotation Processing Example
It is the example project for the annotation processing tutorial.
Stars: ✭ 116 (+205.26%)
Mutual labels:  example, example-project
Play Scala Isolated Slick Example
Example Play Slick Project
Stars: ✭ 155 (+307.89%)
Mutual labels:  example, example-project
Razzle Material Ui Styled Example
Razzle Material-UI example with Styled Components using Express with compression
Stars: ✭ 117 (+207.89%)
Mutual labels:  example, example-project
Jni By Examples
🎇Fun Java JNI By Examples - with CMake and C++ (or C, of course!) ‼️ Accepting PRs
Stars: ✭ 99 (+160.53%)
Mutual labels:  example, example-project
Cppandroidiosexample
An application example using the same C++ code on both an Android project and an iPhone project.
Stars: ✭ 191 (+402.63%)
Mutual labels:  example, example-project
Go Examples
examples written using golang third party packages.
Stars: ✭ 106 (+178.95%)
Mutual labels:  example, example-project
Android Clean Architecture Mvvm Dagger Rx
Implemented by Clean Architecture, Dagger2, MVVM, LiveData, RX, Retrofit2, Room, Anko
Stars: ✭ 138 (+263.16%)
Mutual labels:  example, example-project
Play Samples
Stars: ✭ 335 (+781.58%)
Mutual labels:  example, example-project
Ueberauth example
Example Phoenix application using Überauth for authentication
Stars: ✭ 180 (+373.68%)
Mutual labels:  example, example-project
Owin Webapi Service
✅ OWIN / WebAPI windows service example. Includes attribute based routing sample
Stars: ✭ 175 (+360.53%)
Mutual labels:  example, example-project
Play Java Websocket Example
Example Play Java application showing Websocket usage with Akka actors
Stars: ✭ 86 (+126.32%)
Mutual labels:  example, example-project
Wordpress Plugin Boilerplate Tutorial
Tutorials and Examples for WordPress Plugin Boilerplate, a foundation for WordPress Plugin Development.
Stars: ✭ 232 (+510.53%)
Mutual labels:  example, example-project
Play Scala Slick Example
Example Play Scala project with Slick
Stars: ✭ 59 (+55.26%)
Mutual labels:  example, example-project
Godot public examples
Stars: ✭ 106 (+178.95%)
Mutual labels:  example, example-project
Adhokku
A toy PaaS
Stars: ✭ 32 (-15.79%)
Mutual labels:  example, example-project
Godot tutorials
Code and examples for KidsCanCode Godot Tutorials.
Stars: ✭ 119 (+213.16%)
Mutual labels:  example, example-project
lagom-samples
developer.lightbend.com/start/?group=lagom
Stars: ✭ 85 (+123.68%)
Mutual labels:  example, example-project
Create React App Typescript Todo Example 2020
🚀 Create React App TypeScript Todo Example 2020
Stars: ✭ 255 (+571.05%)
Mutual labels:  example, example-project
Play Java Starter Example
Play starter project in Java (ideal for new users!)
Stars: ✭ 164 (+331.58%)
Mutual labels:  example, example-project
Play Scala Websocket Example
Example Play Scala application showing WebSocket use with Akka actors
Stars: ✭ 194 (+410.53%)
Mutual labels:  example, example-project

Supabase - Flutter

Working with Supabase in Flutter!

YouTube Video Views YouTube Video Votes
Aditya Thakur | YouTubeUsing Supabase with Flutter : https://youtu.be/fqfHEZvQPlY


What is Supabase?

Supabase is the Open Source Firebase Alternative. Supabase is a relational database whereas Firebase is a NoSQL database

Getting Started

  • Add dependency supabase: ^0.0.1-dev.9 to pubspec.yaml of your Flutter project.
  • Create a New Project on https://supabase.io/
  • Get the URL and Key by going to Settings -> API of your Supabase Project.

Create two variables:

  • const supabaseUrl = '<Replace with your URL>';
  • const supabaseKey = '<Replace with your Key>';

Initialise a client to perform operation.

  • final client = SupabaseClient(supabaseUrl, supabaseKey);

Authentication

The LoginScreen of the application has a simple button which when pressed signs up a user.

Code for LoginScreen:

import 'package:flutter/material.dart';  
import 'package:supabase_flutter/homepage.dart';  
import 'package:supabase_flutter/supabase_manager.dart';  
  
class LoginScreen extends StatelessWidget {  
  SupabaseManager supabaseManager = SupabaseManager();  
  
  @override  
  Widget build(BuildContext context) {  
    return Scaffold(  
        body: Container(  
            padding: EdgeInsets.all(50),  
            child: Align(  
                alignment: Alignment.center,  
                child: FlatButton(  
                    color: Colors.black,  
                    shape: RoundedRectangleBorder(  
                      borderRadius: BorderRadius.circular(20),  
                    ),  
                    onPressed: ()  async {  
                      await supabaseManager.signUpUser('[email protected]', 'password');  
                      print('Signed Up');  
                      Navigator.pushReplacement(context, MaterialPageRoute(builder: (context)=> HomePage()));  
                    },  
                    child: Padding(  
                        padding: EdgeInsets.all(10),  
                        child: Row(  
                          mainAxisAlignment: MainAxisAlignment.center,  
                          crossAxisAlignment: CrossAxisAlignment.center,  
                          children: <Widget>[  
                            Icon(Icons.account_circle, color: Colors.white),  
                            SizedBox(width: 10),  
                            Text(  
                                'Sign into to Supabase',  
                                style: TextStyle(color: Colors.white))  
                          ],  
                        )  
                    )  
                )  
            )  
        )  
    );  
  }  
}

The signUpUser function is defined as:

void signUpUser(String email, String password) async {  
  await client.auth.signUp(email, password);  
}

Home Page

The HomePage has a simple UI with two buttons. Read Button prints the data from table to console and Add Button adds data to table.

Note: Create a new table in database where the data will be stored. For this example I have made a table called datatable.

import 'package:flutter/material.dart';  
import 'package:supabase_flutter/supabase_manager.dart';  
  
class HomePage extends StatelessWidget {  
  SupabaseManager supabaseManager = SupabaseManager();  
  
   @override  
  Widget build(BuildContext context) {  
    return Scaffold(  
      body: SafeArea(  
        child: Container(  
          height: MediaQuery.of(context).size.height,  
          width: MediaQuery.of(context).size.width,  
          child: Column(  
            mainAxisAlignment: MainAxisAlignment.center,  
            crossAxisAlignment: CrossAxisAlignment.center,  
            children: [  
              RaisedButton(  
                onPressed: () async {  
                 await supabaseManager.getData();  
                 print('Got Data');  
                },  
                child: Text('Read Data'),  
              ),  
              RaisedButton(  
                onPressed: () async {  
                  await supabaseManager.addData('friendName');  
                  print('added data');  
                },  
                child: Text('Add Data'),  
              )  
            ],  
          ),  
        ),  
      ),  
    );  
  }  
}

Reading Data

The getData function reads data from the table and prints to console:

  
getData() async {  
  var response = await client.from('datatable').select().execute();  
  if (response.error == null) {  
    print('response.data: ${response.data}');  
  }  
}

Insert Data

The addData function inserts data into the table:

addData(String friendName) async {  
  await client.from('datatable').insert([{'name': friendName}]).execute();  
}

Thank you :)

My knowledge of relational databases is limited but I'll continue working with Supabase and would love to see how it evolves.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].