Skip to content

Instantly share code, notes, and snippets.

@nextdev1111
Last active July 24, 2022 03:59
Show Gist options
  • Save nextdev1111/8cdb7c39a49b86c4bc5b824c99dea509 to your computer and use it in GitHub Desktop.
Save nextdev1111/8cdb7c39a49b86c4bc5b824c99dea509 to your computer and use it in GitHub Desktop.
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