搜索插件、代码仓与 APP 分类

插件详情v0.9.8

firedart

Firebase Auth 和 Firestore SDK 的 Dart 原生实现。

AndroidiOSmacOSWindowsLinux
近 30 天下载
4260
喜欢数
319
Pub 分数
140

安装插件

flutter pub add firedart

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Firedart 是 Firebase Auth 和 Firestore 的 Dart 原生实现,使 Flutter 应用程序能够在不依赖平台特定 SDK 的情况下与 Firebase 服务交互。它提供了一种纯 Dart 解决方案,用于身份验证和实时数据管理,可在 Android、iOS、macOS、Windows 和 Linux 上实现无缝集成。通过避免原生依赖,它简化了跨平台开发并减少了应用大小。Firedart 支持身份验证流程、文档和集合操作、查询以及实时监听器,非常适合需要离线功能和低延迟更新的应用。

适合场景

  • 跨平台 Firebase 集成
  • 离线优先的应用程序
  • 实时数据同步
  • 无服务器后端替代方案
  • 轻量级 Firebase 解决方案

主要特点

  • 纯 Dart 实现
  • 支持 Firebase Auth 和 Firestore
  • 实时监听器
  • 离线持久化
  • 平台无关设计

适合对象

  • 寻求无原生依赖的 Firebase 访问的开发者
  • 面向多个平台的应用程序
  • 优先考虑最小应用大小的项目
  • 原型和轻量级应用
  • 避免使用 Google Play Services 的团队

使用建议

  • 仅限 Firebase Auth 和 Firestore 功能
  • 未获得谷歌官方支持
  • 可能缺少高级 Firebase 功能
  • 早期成熟度
  • 无内置云函数支持

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Firedart 🔥🎯

pub package

A dart-native implementation of the Firebase Auth and Firestore SDKs.

This library attempts to minimize dependencies with the intention of making it able to run in any environment capable of executing dart code. Currently it has been successfully tested using the dart runtime (x86-64 and arm32) as well as on Flutter Android, iOS and Desktop.

Firedart currently implements a subset of Firebase Auth and Firestore.

Dependencies

Add Firedart to your pubspec.yaml file:

dependencies:
  firedart: [latest version]

Firebase Auth

The FirebaseAuth class implements the necessary functionality for managing accounts. It currently only supports Email/Password sign-in and anonymous sign-in, so make sure these are enabled under Authentication -> Sign-in Method.

You'll also need to go to your Firebase Console, open Project Settings and under the General tab copy the Web API Key.

Note: in order to reduce external dependencies this library doesn't include a mechanism for persisting tokens. Please look at the following examples based on SharedPreferences and Hive.

Usage
import 'package:firedart/firedart.dart';

FirebaseAuth has a singleton version which should be enough for most use cases. You'll need to initialise it with your API key and a token store (see note above):

FirebaseAuth.initialize(apiKey, await HiveStore.create());
await FirebaseAuth.instance.signIn(email, password);
var user = await FirebaseAuth.instance.getUser();

Alternatively you can instantiate your own FirebaseAuth object:

var firebaseAuth = FirebaseAuth.(apiKey, await PreferencesStore());
await firebaseAuth.signIn(email, password);
var user = await firebaseAuth.getUser();

Further usage examples can be found in the integration tests.

Authentication providers
  • Anonymous
  • Email/Password
  • Custom tokens
  • Google app credentials (i.e. service-account.json)

Firestore

The Firestore class is a basic implementation of the service's RPC interface. The API is similar (but not identical) to that of the official SDK.

Usage
import 'package:firedart/firedart.dart';

As with FirebaseAuth, Firestore offers a singleton version that needs to be initialised with your Project ID, which you can find under Project Settings -> General:

Firestore.initialize(projectId);
var map = await Firestore.instance.collection("users").get();
var users = UserCollection.fromMap(map);

You can also instantiate your own Firestore object. Please note that if your database requires authenticated access, you'll need to pass along an instance of FirebaseAuth.

var firebaseAuth = FirebaseAuth.(apiKey, await HiveStore());
var auth = TokenAuthenticator.from(auth)?.authenticate;
var firestore = Firestore(projectId, authenticator: firebaseAuth);

await firebaseAuth.signIn(email, password);
var map = await firestore.collection("users").get();
var users = UserCollection.fromMap(map);

Further usage examples can be found in the integration tests.

Limitations
  • Collection queries (limit, sort, etc.) are currently not supported.
  • The data is not cached locally.
  • Failed writes (e.g. due to network errors) are not retried.
  • Closed streams are not automatically recovered.
Regenerating the RPC stubs

The Firestore RPC stubs are based on Google's official protobuf definition files from googleapis.

To regenerate them, you will need to check out both googleapis and protobuf.

Set the PROTOBUF and GOOGLEAPIS environment variables to point to your clones of the above repositories respectively, and then run:

$ tool/regenerate.sh

Debugging

For debugging Firebase Auth you can use VerboseClient, an HTTP client that logs all communication to the console. The logs can expose sensitive data including passwords and keys, so it's recommended to only enable it for development builds. In Flutter this can be achieved using the kReleaseMode constant from the foundation package:

var client = !kReleaseMode ? VerboseClient() : http.Client();
var firebaseAuth = FirebaseAuth(apiKey, await PreferencesStore(), httpClient: client);

Securing Tokens

If you're running your code in an environment that requires securing access tokens, you can extend TokenStore to persist data in a secure maner, e.g. by encrypting the data or storing it in an external vault. Example implementations can be found in token_store.dart.

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目