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

插件详情v1.1.0

deeplink_rpc

一个用 Dart 编写的通过深度链接进行 RPC 通信的库。专为 Flutter 移动应用(iOS / Android)设计。

AndroidiOSmacOSWindowsLinux
近 30 天下载
142
喜欢数
4
Pub 分数
130

安装插件

flutter pub add deeplink_rpc

插件介绍

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

一个基于 Dart 的库,通过深度链接在 Flutter 应用程序中实现 RPC(远程过程调用)通信,适用于 iOS 和 Android。它利用深度链接 URL 在应用程序之间或单个应用程序的组件内调用方法和交换数据,实现安全、跨平台的互应用通信。该库专为无缝集成移动环境而设计,支持结构化消息传递,非常适合需要应用间交互但不依赖传统网络调用的场景。该库是开源的,由 Archethic Foundation 维护。

适合场景

  • 应用间通信
  • Flutter 应用中的模块间消息传递
  • 安全的远程方法调用
  • 通过深度链接处理外部操作
  • 简化导航与数据传输

主要特点

  • 基于深度链接的 RPC
  • 跨平台支持(iOS/Android)
  • 安全的消息序列化
  • 与 Flutter 的轻松集成
  • 开源且积极维护

适合对象

  • 使用 Flutter 的移动应用开发者
  • 需要应用间通信的应用
  • 开发人员实现安全的深度链接工作流程
  • 需要轻量级 RPC 替代方案的项目
  • 构建模块化或微前端架构的团队

使用建议

  • 目标平台需要正确的深度链接配置
  • 仅限移动和桌面平台(无网页)
  • 依赖于正确的URL方案设置
  • 可能需要为敏感数据采取额外的安全措施
  • 不适用于高频或低延迟通信

原始 README

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

Deeplink RPC

A RPC-via-deeplink communication library coded in Dart. This is dedicated to Flutter mobile applications (iOS / Android).

Protocol

Deeplink codec

Deeplink messages are appended to the deeplink URI. Because of that, there are limitations in the available formatting.

To get it working, the message is encoded that way :

                     +--------------+   +------+   +-----------+
method_payload :     | Json Message |-> | gzip |-> | base64Url |
                     +--------------+   +------+   +-----------+


Deeplink Url : `<scheme>://<host>/<method_name>/<method_payload>`

Example :

                     +--------------------------+      +----------------------------------------------------------------+
method_payload :     | { "param1" : "a_value" } |----> | "H4sIAAAAAAAAA6tWUCpILErMNVRSsFJQSowvS8wpTVVSqAUAhIgKchgAAAA=" |
                     +--------------------------+      +----------------------------------------------------------------+


Deeplink Url : `scheme://host/a_method/H4sIAAAAAAAAA6tWUCpILErMNVRSsFJQSowvS8wpTVVSqAUAhIgKchgAAAA=`

Request formatting

Requests payload are encapsulated in a JSON-RPC 2.0 message.

{
  "id": Number,                     // An unique client-generated integer identifying the request
  "replyUrl": String,               // Deeplink URL to which send the invokation result. This should be a Deeplink URL handled by the DApp.
  "params": {
    "origin": {
      "name": String,               // Human readable identifier of the DApp
      "url": String | undefined,    // URL of the DApp
      "logo": Base64 | undefined,   // Logo of the DApp 
    },
    "version": 2,                   // Version of the DApp API
    "payload": Object,              // Method parameters
  }
}
Success Response formatting
{
  "id": Number,                     // The request identifier
  "result":  Object,                // Result payload
}
Failure Response formatting
{
  "id": Number,                     // The request identifier
  "failure": {
    "code": Number,                 // Error code
    "message": String | undefined,  // Error description
    "data": Object | undefined,     // Error data
  },
}

Usage

Server - listening to incoming requests
/// 1. Enable deeplinking for your application (https://docs.flutter.dev/development/ui/navigation/deep-linking)

/// 2. Declare the deeplink-rpc receiver
/// When a RPC call <scheme>://a_rpc_command/<payload> is received, the payload is decoded
/// and transmitted to the `handle` method.
final _deeplinkRpcServer = DeeplinkRpcServer()
    ..registerHandler(
      DeeplinkRpcRequestHandler(
        route: const DeeplinkRpcRoute('a_rpc_command'),
        handle: (request) {
            log('Command received');
        }
      ),
    );


class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'DeeplinkRPC Demo',
      home: const SendForm(),
      onGenerateRoute: (settings) {
        /// 3. Listen to incoming deeplink requests
        if (_deeplinkRpcServer.handleRoute(settings.name)) return;

        // ... do other route generation stuffs here.
        return null;
      },
    );
  }
}
Client - Sending requests and listening for responses
/// 1. Enable deeplinking for your application (https://docs.flutter.dev/development/ui/navigation/deep-linking)
/// It is necessary to receive responses.

/// 2. Declare the deeplink-rpc client
/// When a RPC call <scheme>://a_rpc_command/<payload> is received, the payload is decoded
/// and transmitted to the `handle` method.
final _deeplinkRpcClient = DeeplinkRpcClient();

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'DeeplinkRPC Demo',
      onGenerateRoute: (settings) {
        /// 3. Listen to incoming deeplink requests
        if (_deeplinkRpcClient.handleRoute(settings.name)) return;

        // ... do other route generation stuffs here.
        return null;
      },
      home: Scaffold(
        floatingActionButton: FloatingActionButton(
          child: const Icon(Icons.send),
          onPressed: () async {
            final response = await _deeplinkRpcClient.send(
              timeout: const Duration(seconds: 5),
              request: DeeplinkRpcRequest(
                requestUrl: 'serverapp://server.app/request_endpoint',
                replyUrl: 'clientapp://client.app/reply_endpoint',
                params: {
                  'param1': 'value1',
                  'param2': 'value2',
                },
              ),
            );

            response.map(
              failure: (failure) {
                log(
                  'RPC request failed',
                  error: failure,
                );
                ScaffoldMessenger.of(context).showSnackBar(
                  SnackBar(
                      content: Text(failure.message ?? "An error occured")),
                );
              },
              success: (result) {
                log(
                  'RPC request succeed : ${json.encode(result)}',
                );
                ScaffoldMessenger.of(context).showSnackBar(
                  SnackBar(content: Text(json.encode(result))),
                );
              },
            );
          },
        ),
        body: const SafeArea(
          child: Padding(
            padding: EdgeInsets.all(8.0),
            child: Center(
              child: Text('Client example'),
            ),
          ),
        ),
      ),
    );
  }
}

所属分类

依赖

依赖清单 6 项

源码仓库

使用此插件的项目