简体   繁体   English

在 dart flutter 和非 flutter dart 应用程序之间共享 supabase 代码的最佳方式?

[英]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. Supabase为非flutter应用提供supabase-dart,为flutter应用提供supabase-flutter。 (The pubspec in supabase-flutter apears to use the supabase-dart package.) (supabase-flutter 中的 pubspec 似乎使用 supabase-dart package。)

I have dart code files that comprise a data access layer (for the postgres db) written for supabase.我有 dart 个代码文件,其中包含为 supabase 编写的数据访问层(用于 postgres 数据库)。 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.我想在用 dart 编写的非颤动服务器和当然在 flutter 中的移动应用程序之间共享 dart 代码文件。

The imports in each code file of the flutter app all use: flutter app的每个代码文件中的imports都使用了:

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.所以,我不一定想把那些代码文件带到非flutter,dart服务器,因为他们使用supabase_flutter。

I have the exact same code files in the non-flutter, dart server but I replaced the imports with:我在非 flutter dart 服务器中有完全相同的代码文件,但我将导入替换为:

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?对于这些共享文件,是否可以在 flutter 和非 flutter 应用程序中仅使用 non-flutter 导入?

(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.) (我已经尝试了一些这方面的组合并且事情似乎有效,但我不知道是否有我需要关注的事情因为文档说使用一个 package 用于 flutter 而另一个用于非颤动。 )

For these shared files, is it ok to just use the non-flutter import in both the flutter and non-flutter apps?对于这些共享文件,是否可以在 flutter 和非 flutter 应用程序中仅使用 non-flutter 导入?

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! supabase_flutter package 只是supabase package 包裹着一些 Flutter 特定代码,主要是为了带来 auth 持久性,所以你应该为一些常见的部分导入supabase package !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM