Skip to content

Commit 303229d

Browse files
simolus3benitav
andauthored
Add docs on using FlutterFlow with custom connector (#183)
* Add docs on using FlutterFlow with custom connector * Add a note to the introduction --------- Co-authored-by: benitav <benita@journeyapps.com>
1 parent 3dc5c73 commit 303229d

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

integration-guides/flutterflow-+-powersync.mdx

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Used in conjunction with **FlutterFlow**, PowerSync enables developers to build
2424
Note that using libraries in FlutterFlow requires being on a [paid plan with FlutterFlow](https://www.flutterflow.io/pricing). If this is not an option for you, you can use our [legacy guide](/integration-guides/flutterflow-+-powersync/powersync-+-flutterflow-legacy) with custom code to integrate PowerSync in your FlutterFlow project.
2525
</Tip>
2626

27+
<Note>
28+
This guide uses **Supabase** as the backend database provider for its seamless integration with PowerSync. However, you can integrate a different backend using custom actions. For more information, refer to the [Custom backend connectors](#custom-backend-connectors) section.
29+
</Note>
30+
2731
## Guide Overview
2832

2933
<Note>
@@ -595,7 +599,7 @@ bucket_definitions:
595599
**Checkpoint:** Your app should continue running seamlessly as before.
596600
</Check>
597601

598-
## Arrays, JSON and other types
602+
## Arrays, JSON and Other Types
599603

600604
For column values, PowerSync supports three basic types: Integers, doubles, and strings. These types have been chosen because
601605
they're natively supported by SQLite while also being easy to transport as JSON.
@@ -671,6 +675,48 @@ This allows you to customize how individual values are represented for Postgres.
671675
column of the `lists` table is decoded as JSON so that it's uploaded as a proper array while being stored
672676
as a list locally.
673677

678+
## Custom Backend Connectors
679+
680+
To enable an easy setup, the PowerSync FlutterFlow library integrates with Supabase by default. This means
681+
that as long as you use Supabase for authentication in your app, PowerSync will automatically connect as
682+
soon as users log in, and can automatically upload local writes to a Supabase database.
683+
684+
For apps that don't use Supabase, you can disable this default behavior and instead rely on your own
685+
backend connectors.
686+
For this, create your own custom action (e.g. `applyPowerSyncOptions`). It's important that this action runs
687+
before anything else in your app uses PowerSync, so add this action to your `main.dart` as a final action.
688+
689+
```dart
690+
import 'package:power_sync_b0w5r9/custom_code/actions/initialize_power_sync.dart';
691+
import 'package:powersync/powersync.dart' as ps;
692+
693+
Future applyPowerSyncOptions() async {
694+
// Disable the default Supabase integration
695+
powerSyncOptions.useSupabaseConnector = false;
696+
final db = await getOrInitializeDatabase();
697+
698+
// TODO: Write your own connector and call connect/disconnect when a user logs
699+
// in.
700+
db.connect(connector: _MyCustomConnector());
701+
}
702+
703+
final class _MyCustomConnector extends ps.PowerSyncBackendConnector {
704+
@override
705+
Future<ps.PowerSyncCredentials?> fetchCredentials() {
706+
// TODO: implement fetchCredentials
707+
throw UnimplementedError();
708+
}
709+
710+
@override
711+
Future<void> uploadData(ps.PowerSyncDatabase database) {
712+
// TODO: implement uploadData
713+
throw UnimplementedError();
714+
}
715+
}
716+
```
717+
718+
For more information on writing backend connectors, see [integrating with your backend](/client-sdk-references/flutter#3-integrate-with-your-backend).
719+
674720
## Known Issues, Limitations and Gotchas
675721

676722
Below is a list of known issues and limitations.

0 commit comments

Comments
 (0)