Demo app demonstrating use of the PowerSync SDK for Flutter together with Supabase. For a step-by-step guide, see here.
Ensure you have melos installed.
cd demos/supabase-todolist
melos prepare
cp lib/app_config_template.dart lib/app_config.dart
- Insert your Supabase and PowerSync project credentials into
lib/app_config.dart
(See instructions below) flutter run
Create a new Supabase project, and paste an run the contents of database.sql in the Supabase SQL editor.
It does the following:
- Create
lists
andtodos
tables. - Create a publication called
powersync
forlists
andtodos
. - Enable row level security, allowing users to only view and edit their own data.
- Create a trigger to populate some sample data when an user registers.
Create a new PowerSync instance, connecting to the database of the Supabase project.
Then deploy the following sync rules:
bucket_definitions:
user_lists:
priority: 1
parameters: select id as list_id from lists where owner_id = request.user_id()
data:
- select * from lists where id = bucket.list_id
user_todos:
parameters: select id as list_id from lists where owner_id = request.user_id()
data:
- select * from todos where list_id = bucket.list_id
Note: These rules showcase prioritized sync,
by syncing a user's lists with a higher priority than the items within a list (todos). This can be
useful to keep the list overview page reactive during a large sync cycle affecting many
rows in the user_todos
bucket. The two buckets can also be unified into a single one if
priorities are not important (the app will work without changes):
bucket_definitions:
user_lists:
# Separate bucket per todo list
parameters: select id as list_id from lists where owner_id = request.user_id()
data:
- select * from lists where id = bucket.list_id
- select * from todos where list_id = bucket.list_id
Insert the credentials of your new Supabase and PowerSync projects into lib/app_config.dart