deeplink_rpc 1.0.6 copy "deeplink_rpc: ^1.0.6" to clipboard
deeplink_rpc: ^1.0.6 copied to clipboard

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

example/lib/main.dart

/// SPDX-License-Identifier: AGPL-3.0-or-later
import 'dart:convert';
import 'dart:developer';
import 'package:deeplink_rpc/deeplink_rpc.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

final _deeplinkRpcClient = DeeplinkRpcClient();

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

  final _messengerKey = GlobalKey<ScaffoldMessengerState>();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      scaffoldMessengerKey: _messengerKey,
      title: 'DeeplinkRPC Demo',
      onGenerateRoute: (settings) {
        if (_deeplinkRpcClient.handleRoute(settings.name)) return;
        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,
                );
                _messengerKey.currentState?.showSnackBar(
                  SnackBar(
                    content: Text(failure.message ?? 'An error occured'),
                  ),
                );
              },
              success: (result) {
                log(
                  'RPC request succeed : ${json.encode(result)}',
                );
                _messengerKey.currentState?.showSnackBar(
                  SnackBar(content: Text(json.encode(result))),
                );
              },
            );
          },
        ),
        body: const SafeArea(
          child: Padding(
            padding: EdgeInsets.all(8),
            child: Center(
              child: Text('Client example'),
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
110
pub points
61%
popularity

Publisher

verified publisherarchethic.net

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

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

AGPL-3.0 (LICENSE)

Dependencies

archive, flutter, freezed_annotation, json_annotation, url_launcher, uuid

More

Packages that depend on deeplink_rpc