搜尋分類、套件與程式碼儲存庫

套件詳情v1.0.3

firebase_database_rest

一個基於 REST 的跨平台 Dart/Flutter 包裝器,用於 Firebase 實時資料庫 API。

近 30 天下載
38
喜歡數
18
Pub 分數
140

安裝套件

flutter pub add firebase_database_rest

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個與平台無關的 Dart/Flutter 套件,為 Firebase 實時資料庫提供基於 REST 的封裝。它可透過 HTTP 請求實現與 Firebase 資料庫的無縫互動,適用於無法使用原生 Firebase SDK 的環境。該套件將底層 REST 呼叫抽象為直覺的 Dart 方法,支援資料讀取、寫入以及透過輪詢實作的即時更新。設計簡潔且跨平台相容,非常適合需要 Firebase 整合卻不依賴平台特定外掛程式之應用。

適用情境

  • 跨平台 Firebase 資料庫存取
  • 伺服器端Flutter應用程式
  • Web 和桌面應用程式整合
  • 離線優先場景下的手動同步
  • 輕量級 Firebase 互動

主要特色

  • 基於REST API的通訊
  • 平台無關的設計
  • 簡單的 CRUD 操作
  • 基於輪詢的即時更新
  • 無原生 SDK 依賴項

適合對象

  • 面向網路或桌面的開發人員
  • 避免使用原生 Firebase 插件的項目
  • 使用Flutter的後端服務
  • 需要輕量級 Firebase 存取的 App

使用建議

  • 手動處理即時更新
  • 比原生 SDK 的延遲更高
  • 僅限 REST 相容功能
  • 無內建離線持久化
  • 需要手動處理錯誤和重試邏輯

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

firebase_database_rest

Continous Integration Pub Version

A platform independent Dart/Flutter Wrapper for the Firebase Realtime Database API based on REST

Features

  • Pure Dart-based implementation
    • works on all platforms supported by dart
  • Uses the official REST-API endpoints
  • Provides high-level classes to manage database access
  • Supports Model-Binding via Generics and converter functions
  • Full support of all Realtime database features:
    • Supports CRUD
    • Supports Queries (filtering, sorting)
    • Supports realtime server updates (streaming)
    • Supports ETags
  • Provides a Transaction class to wrap ETag-Logic into safe transactions
  • Provides timestamp class for server set timestamps
  • Proivides low-level REST classes for direct API access (import firebase_database_rest/rest.dart)
  • Fully integrated with firebase_auth_rest - including automatic auth token refreshes

Installation

Simply add firebase_database_rest to your pubspec.yaml and run pub get (or flutter pub get).

Usage

The libraries primary class is the FirebaseStore. It is a high-level class that allows access to a certain part of the realtime database using Model binding. With this store, you specify a subpatch and can then perform various operations on elements below that path (list key, create, read, write or delete them, ...). This class also provides the APIs for streaming changes and transactions. Typically, your application would use multiple stores, one for each dataclass you plan to store at a certain path.

The second important class is the FirebaseDatabase. It serves as the toplevel class, parent to all stores and manages the database connection itself, including the management of the associated FirebaseAccount (from firebase_auth_rest) and background ressources (like the REST-API interface).

The following code is a simple example, which can be found in full length, including errorhandling, at https://pub.dev/packages/firebase_database_rest/example. It loggs into firebase as anonymous user, starts streaming changes and then does some db operations.

// The data class that is stored in firebase
class ExampleModel {
  final int id;
  final String data;

  const ExampleModel(this.id, this.data);
  
  // ...
}

// obtain a firebase account, using firebase_auth_rest
final account = // ...

// create a database reference from that account
final database = FirebaseDatabase(
  account: account,
  database: 'my-firebase-realtime-database-name,
  basePath: 'application/${account.localId}/example',
);

// create typed store. In this example, a callback store is used, but you can
// also just extend FirebaseStore
final store = database.createRootStore<ExampleModel>(
  onDataFromJson: (dynamic json) => ExampleModel.fromJson(json),
  onDataToJson: (data) => data.toJson(),
  onPatchData: (data, updatedFields) => data.patch(updatedFields),
);

// add a stream listener that reports database changes in realtime
sub = (await store.streamAll()).listen((e) => print('Stream update: $e'));

// add some data to the store
await store.create(const ExampleModel(1, 'A'));

// get all data in store
print('All data: ${await store.all()}');

// cleanup: stop streaming and dispose of the database
await sub.cancel();
await database.dispose();

Documentation

The documentation is available at https://pub.dev/documentation/firebase_database_rest/latest/. A full example can be found at https://pub.dev/packages/firebase_database_rest/example.

所屬分類

依賴

依賴清單 6 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。