Last active
July 24, 2022 03:59
-
-
Save nextdev1111/8cdb7c39a49b86c4bc5b824c99dea509 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter_supabase_yt_1/models/models.dart'; // this is being used to import the todo.dart from models file. | |
import 'package:supabase_flutter/supabase_flutter.dart'; | |
class SupabaseDataManager { | |
// create function which takes one argument of Todo | |
Future<PostgrestResponse<dynamic>> createData(Todo todo) async { | |
PostgrestResponse<dynamic> res = await Supabase.instance.client | |
.from('todos') | |
// here 👇 you need to make todo.toMap() because we need to make Todo model to map --> eg Todo(title: 'This is first todo') -> {'title': 'This is first todo'} | |
.insert(todo.toMap()) | |
.execute(); | |
return res; | |
} | |
// read function | |
Future<PostgrestResponse<dynamic>> readData() async { | |
PostgrestResponse<dynamic> res = await Supabase.instance.client | |
.from('todos') | |
.select('id, title') | |
.execute(); | |
return res; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment