Search code examples
flutterdartsupabasesupabase-database

Best way to share supabase code between dart flutter and non-flutter dart applications?


Supabase provides supabase-dart for non-flutter applications and provides supabase-flutter for flutter applications. (The pubspec in supabase-flutter apears to use the supabase-dart package.)

I have dart code files that comprise a data access layer (for the postgres db) written for supabase. I'd like to share the dart code files between a non-flutter, server written in dart and a mobile app that of course is in flutter.

The imports in each code file of the flutter app all use:

import 'package:supabase_flutter/supabase_flutter.dart';

So, I didn't necessarily want to bring those code files into the non-flutter, dart server because they use supabase_flutter.

I have the exact same code files in the non-flutter, dart server but I replaced the imports with:

import 'package:supabase/supabase.dart';

And, it works fine, but I have to maintain two versions of essentially the same file.

For these shared files, is it ok to just use the non-flutter import in both the flutter and non-flutter apps?

(I have tried some combinations of this and things seem to work, but I don't know if there is something I need to be concerned about on this since the docs say to use one package for flutter and the other for non-flutter.)


Solution

  • For these shared files, is it ok to just use the non-flutter import in both the flutter and non-flutter apps?

    Short answer yes.

    supabase_flutter package is just supabase package wrapped with some Flutter specific code mainly to bring auth persistence, so you should be fine importing supabase package for some common pieces!