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

插件详情v0.2.0

firebaseapis

通过 API 发现服务描述的 Google API 的自动生成客户端库。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
2.1万
喜欢数
21
Pub 分数
160

安装插件

flutter pub add firebaseapis

插件介绍

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

firebaseapis 包通过 API 发现服务为访问 Google API 提供了自动生成的客户端库。专为 Flutter 和 Dart 构建,它能够通过从官方 API 描述生成类型安全的 API,实现与 Firebase 及其他 Google 服务的无缝集成。这使开发者可以直接在 Android、iOS、Web、macOS、Windows 和 Linux 平台上,与其庞大的生态系统(如 Drive、日历和云存储)进行交互。该包由 invertase.io 维护,支持现代 Flutter 开发工作流程。

适合场景

  • 与 Google Drive 集成
  • 访问 Google 日历数据
  • 从 Google 身份验证获取用户信息
  • 管理云存储操作
  • 与 Google 表格同步数据
  • 连接到 YouTube 数据 API

主要特点

  • 从官方 API 发现文档自动生成
  • 类型安全的 Dart 接口
  • 跨平台支持(Android、iOS、Web、macOS、Windows、Linux)
  • 与 Firebase 项目的无缝集成
  • 支持 OAuth2 认证流程
  • 定期更新,包含新的 Google API 发布

适合对象

  • 需要 Google API 访问权限的开发者构建应用程序
  • 需要与多个 Google 服务集成的项目
  • 跨平台应用程序,适用于所有主要操作系统
  • 使用 Firebase 作为后端基础设施的团队
  • 需要对 Google 服务进行安全、经过身份验证的 API 调用的应用程序

使用建议

  • 需要了解 Google API 发现格式
  • 身份验证设置(OAuth2)可能很复杂
  • 大型生成的代码库可能会增加构建大小
  • 除了生成的 API 参考文档外,文档有限
  • 对于轻量级客户端即可满足的简单用例来说,不是理想选择

原始 README

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

Firebase API Client Libraries for Dart

Chat on Discord

melos

This is based on the googleapis.dart repository but instead aimed at supporting Firebase related APIs only. Additionally, this adds support for several unlisted (but discoverable) Firebase APIs that are not listed on the official discovery API that googleapis.dart uses (and is currently limited to) as well as several private APIs (APIs that require an API key to view discovery information).

See ./generated/firebaseapis/README.md for information on all the currently supported APIs.

Usage Example

// Import the APIs you want to use
import 'package:firebaseapis/firebaseremoteconfig/v1.dart' as remote_config;
import 'package:firebaseapis/firebaserules/v1.dart' as firebase_rules;
// Import Auth client
import 'package:googleapis_auth/auth_io.dart' as auth;

// Get an Auth Client
final authClient = await auth.clientViaApplicationDefaultCredentials(scopes: [
  remote_config.FirebaseRemoteConfigApi.cloudPlatformScope,
]);

// Call some APIs
final rc = remote_config.FirebaseRemoteConfigApi(authClient);
final config =
  await rc.projects.getRemoteConfig('projects/<your-project-id>');
print(config.parameters);
print(config.parameters?.values.first.defaultValue);
print(config.parameters?.values.first.description);
print(config.parameters?.values.first.valueType);

final fr = firebase_rules.FirebaseRulesApi(authClient);
final rules =
  await fr.projects.rulesets.list('projects/<your-project-id>');
print(rules.rulesets?.first.name);
print(rules.rulesets?.first.source?.files?.first.content);

Custom Request Headers

Custom request headers can be set by adding to requestHeaders:

import 'package:firebaseapis/src/user_agent.dart';

Future<void> main() async {
  requestHeaders.addAll({
    'cool-header': 'cool-value',
  });
  print(requestHeaders);
}

Contributing

This project uses Melos to manage the project and dependencies.

To install Melos, run the following command from your SSH client:

dart pub global activate melos

Next, at the root of your locally cloned repository bootstrap the projects dependencies:

melos bootstrap

The bootstrap command locally links all dependencies within the project without having to provide manual dependency_overrides. This allows all plugins, examples and tests to build from the local clone project.

You do not need to run flutter pub get once bootstrap has been completed.

Adding a new API

To add a new API and generate library code for it is fairly straightforward;

  1. Add the API to the apis list in ./config.yaml
  2. Run melos run config:download to update the downloaded discovery document JSON files that are in ./discovery.
    • Note: several APIs require an API key to be able to read the discovery information. Set a API_KEY environment variable before running the command to be able to download the discovery documents for these private APIs, e.g. API_KEY=<your-key-here> melos run config:download.
  3. Run melos run config:generate to generate new Dart library code for the API, which outputs to ./generated/firebaseapis.

Maintained by Invertase.

所属分类

依赖

依赖清单 2 项

  • _discoveryapis_commons^1.0.0
  • http>=0.13.0 <2.0.0

源码仓库

使用此插件的项目