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

插件详情v2.1.0

firebase_admin_interop

Firebase Admin SDK for Dart,是官方 Node.js SDK 的封装。

近 30 天下载
134
喜欢数
25
Pub 分数
40

安装插件

flutter pub add firebase_admin_interop

插件介绍

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

Firebase Admin SDK for Dart,作为官方 Node.js SDK 的包装器实现。它通过互操作性利用原生 Node.js 功能,在 Dart 环境中启用服务器端 Firebase 操作。该包非常适合需要对 Firebase 资源(如身份验证、Firestore 和消息传递)进行管理访问的后端服务、云函数和服务器应用程序。对于已经熟悉 Node.js 上 Firebase Admin 的开发人员,它提供了熟悉的 API。

适合场景

  • 服务器端 Firebase 管理
  • 使用 Dart 的云函数
  • 后端服务集成
  • 身份验证管理
  • Firestore 数据操作

主要特点

  • Node.js SDK 包装器
  • 管理员级 Firebase 访问
  • Dart 兼容接口
  • 与现有 Firebase 工作流程无缝集成
  • 支持多个 Firebase 服务

适合对象

  • 使用 Dart 的后端开发人员
  • 需要 Firebase 管理员访问权限的服务器应用程序
  • 云函数环境
  • 需要 Firebase 身份验证控制的项目
  • 熟悉 Firebase Admin on Node.js 的团队

使用建议

  • 需要 Node.js 运行时环境
  • 仅限服务器端使用场景
  • 不适用于Flutter移动应用
  • 依赖外部 Node.js 进程
  • 可能具有平台特定的设置要求

原始 README

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

Build Status

Write server-side Firebase applications in Dart using Node.js as a runtime.

Firestore Timestamps migration:

Firestore deprecated usage of DateTime objects in favor of custom Timestamp type and recommends migrating as soon as possible. By default all timestamps are still returned as DateTime objects and you can access them with DocumentData.getDateTime or DocumentData.setDateTime. To start using Timestamps you must configure Firestore as follows:

final app = FirebaseAdmin.instance.initializeApp();
final firestore = app.firestore();
// Call Firestore.settings at the very beginning before any other calls:
firestore.settings(FirestoreSettings(timestampsInSnapshots: true));
// You can read and write data now, but make sure to use new `setTimestamp` and `getTimestamp`
// methods of `DocumentData`.

Installation

  1. Add this package as a dependency to your pubspec.yaml:
dependencies:
  firebase_admin_interop: [latest_version]

Run pub get.

  1. Create package.json file to install Node.js modules used by this library:
{
  "dependencies": {
    "firebase-admin": "8.5.0",
    "@google-cloud/firestore": "2.0.0"
  }
}

Run npm install.

Usage

Below is a simple example of using Realtime Database client:

import 'dart:async';
import 'package:firebase_admin_interop/firebase_admin_interop.dart';

Future<void> main() async {
  final serviceAccountKeyFilename = '/absolute/path/to/service-account.json';
  final admin = FirebaseAdmin.instance;
  final cert = admin.certFromPath(serviceAccountKeyFilename);
  final app = admin.initializeApp(new AppOptions(
    credential: cert,
    databaseURL: "YOUR_DB_URL",
  ));
  final ref = app.database().ref('/test-path');
  // Write value to the database at "/test-path" location.
  await ref.setValue("Hello world");
  // Read value from the same database location.
  var snapshot = await ref.once("value");
  print(snapshot.val()); // prints "Hello world".
}

Note that it is only possible to use JSON-compatible values when reading and writing data to the Realtime Database. This includes all primitive types (int, double, bool), string values (String) as well as any List or Map instance.

For Firestore there are a few more supported data types, like DateTime and GeoPoint.

Building

This library depends on node_interop package which provides Node.js bindings and build_node_compilers package which allows compiling Dart applications as Node.js modules.

To enable builders provided by build_node_compilers first add following dev dependencies to your pubspec.yaml:

dev_dependencies:
  build_runner: ^1.0.0
  build_node_compilers: ^0.2.0

Next, create build.yaml file with following contents:

targets:
  $default:
    sources:
      - "lib/**"
      - "node/**" # Assuming your main Dart files is in node/ folder (recommended).
      - "test/**"
    builders:
      build_node_compilers|entrypoint:
        options:
          compiler: dart2js # To compile with dart2js by default

You can now build your project using build_runner:

# By default compiles with DDC
pub run build_runner build --output=build

# To compile with dart2js:
pub run build_runner build \
  --define="build_node_compilers|entrypoint=compiler=dart2js" \
  --define="build_node_compilers|entrypoint=dart2js_args=[\"--minify\"]" \ # optional, minifies resulting code
  --output=build/

Status

This library is considered stable though not feature complete. It is recommended to check dev versions for latest updates and bug fixes.

Make sure to checkout CHANGELOG.md after every release, all notable changes and upgrade instructions will be described there.

Current implementation coverage report:

  • [x] admin
  • [x] admin.auth
  • [x] admin.app
  • [x] admin.credential
  • [x] admin.database
  • [x] admin.firestore
  • [x] admin.messaging
  • [ ] admin.storage

Features and bugs

Please file feature requests and bugs at the issue tracker.

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目

暂无相关数据。