搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案