Flutter todo list with Supabase

This is a walkthrough of a small todo app I built with Flutter and Supabase. Todos live in a single Postgres table; the app reads them through the supabase Dart client, shows them in a list, and lets you add, complete and delete them. The full project is on GitHub.
The snippets below have been updated for version 2 of the Supabase Dart client (checked against supabase 2.16.5). The original repo predates that.
The table
Section titled “The table”The app expects a todo table with these columns:
create table todo ( id bigint generated by default as identity primary key, created_at timestamptz not null default now(), title text not null, description text not null, "isDone" boolean not null default false);The camelCase isDone column needs double quotes in SQL, but the client sends it as a plain JSON key, so the Dart code doesn’t need to care.
If row level security is enabled on the table, the app’s public key can only read and write rows that a policy allows. Either add policies for the anon role or, better, add Supabase Auth and write policies per user.
Talking to Supabase
Section titled “Talking to Supabase”All database calls go through one helper class. Constants holds the project URL and the public client key from the Supabase dashboard. Supabase is replacing the legacy anon key with a publishable key (sb_publishable_...); either works here, since both carry the same low privileges.
import 'package:supabase/supabase.dart';import 'package:supabase_flutter_todo/constants.dart';
class SBHelper { static final SupabaseClient supabase = SupabaseClient( Constants.supabaseUrl, Constants.supabaseAnnonKey, );
static Future<List<Map<String, dynamic>>> getAllTodo() async { return await supabase.from('todo').select().order('created_at'); }
static Future<void> addTodo(String title, String description) async { await supabase.from('todo').insert({ 'title': title, 'description': description, 'isDone': false, }); }
static Future<void> setDone(int id, bool isDone) async { await supabase.from('todo').update({'isDone': isDone}).eq('id', id); }
static Future<void> deleteTodo(int id) async { await supabase.from('todo').delete().eq('id', id); }}In v2 of the client, awaiting select() returns the rows directly as a List<Map<String, dynamic>>, and errors are thrown as PostgrestException rather than returned in a response object. insert returns nothing unless you chain .select(), so addTodo returns void.
For a Flutter app, the supabase_flutter package is the more usual choice: you call Supabase.initialize(url: ..., anonKey: ...) once in main() and use Supabase.instance.client everywhere, and it persists auth sessions for you. The plain supabase package used here is fine when you don’t need auth.
The home page
Section titled “The home page”The home page holds a Future<TodoModel> in state and hands it to a FutureBuilder. TodoModel (in lib/model/todo_model.dart in the repo) wraps the list of rows as Todo objects with id, createdAt, title, description and isDone.
Every change awaits the Supabase call and then replaces the future, which makes the FutureBuilder fetch the list again. Tapping the trailing icon toggles a todo; long-pressing deletes it.
import 'package:flutter/material.dart';import 'package:supabase_flutter_todo/api/sp_client.dart';import 'package:supabase_flutter_todo/model/todo_model.dart';import 'package:supabase_flutter_todo/screen/add_todo.dart';
class Homepage extends StatefulWidget { const Homepage({super.key});
@override State<Homepage> createState() => _HomepageState();}
class _HomepageState extends State<Homepage> { late Future<TodoModel> futureTodoList;
@override void initState() { super.initState(); futureTodoList = fetchTodos(); }
Future<TodoModel> fetchTodos() async { final todoList = await SBHelper.getAllTodo(); return TodoModel.fromJson(todoList); }
void refresh() { setState(() { futureTodoList = fetchTodos(); }); }
Future<void> toggleDone(Todo todo) async { await SBHelper.setDone(todo.id, !todo.isDone); if (mounted) refresh(); }
Future<void> deleteTodo(Todo todo) async { await SBHelper.deleteTodo(todo.id); if (mounted) refresh(); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Todo List')), body: Center( child: FutureBuilder<TodoModel>( future: futureTodoList, builder: (context, snapshot) { if (snapshot.hasError) { return Text('${snapshot.error}'); } if (!snapshot.hasData) { return const CircularProgressIndicator(); } final todos = snapshot.data!.todos; return ListView.builder( itemCount: todos.length, itemBuilder: (context, index) { final todo = todos[index]; return ListTile( title: Text(todo.title), subtitle: Text(todo.description), onLongPress: () => deleteTodo(todo), trailing: IconButton( icon: Icon(todo.isDone ? Icons.radio_button_checked_outlined : Icons.radio_button_unchecked_outlined), onPressed: () => toggleDone(todo), ), ); }, ); }, ), ), floatingActionButton: FloatingActionButton( onPressed: () async { await Navigator.push( context, MaterialPageRoute(builder: (context) => const AddTodo()), ); // Reload when coming back from the add page. if (mounted) refresh(); }, backgroundColor: Colors.green, child: const Icon(Icons.add), ), ); }}An earlier version of this page didn’t await setDone and instead refreshed after a fixed 500 ms delay, hoping the update had landed by then. Awaiting the call is both faster and reliable. It also had a tap menu with a “Delete” item that wasn’t wired to anything; long-press delete replaces it.
Adding a todo
Section titled “Adding a todo”AddTodo is a form with two required fields. On submit it waits for the insert to finish before popping back, so the home page’s refresh sees the new row.
import 'package:flutter/material.dart';import 'package:supabase_flutter_todo/api/sp_client.dart';
class AddTodo extends StatefulWidget { const AddTodo({super.key});
@override State<AddTodo> createState() => _AddTodoState();}
class _AddTodoState extends State<AddTodo> { final _formKey = GlobalKey<FormState>(); final titleController = TextEditingController(); final descController = TextEditingController();
@override void dispose() { titleController.dispose(); descController.dispose(); super.dispose(); }
Future<void> submit() async { if (!_formKey.currentState!.validate()) return; await SBHelper.addTodo(titleController.text, descController.text); if (mounted) Navigator.pop(context); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Add Todo')), body: Form( key: _formKey, child: Padding( padding: const EdgeInsets.all(16.0), child: Column( children: [ TextFormField( controller: titleController, decoration: const InputDecoration( border: OutlineInputBorder(), labelText: 'Title', ), validator: (value) => (value == null || value.isEmpty) ? 'Please enter title' : null, ), const SizedBox(height: 16.0), TextFormField( controller: descController, decoration: const InputDecoration( border: OutlineInputBorder(), labelText: 'Description', ), validator: (value) => (value == null || value.isEmpty) ? 'Please enter description' : null, ), const SizedBox(height: 16.0), ElevatedButton( onPressed: submit, child: const Text('Submit'), ), ], ), ), ), ); }}Next steps
Section titled “Next steps”- The list is fetched on demand. To see changes made from another device without refreshing, use the client’s
stream()method on the table, which is built on Supabase Realtime (Realtime has to be enabled for the table). - There is no error handling around the writes yet. Wrap the calls in
try/on PostgrestExceptionand show aSnackBarif something fails.
References
Section titled “References”© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)