rx_method_channel 0.0.1 copy "rx_method_channel: ^0.0.1" to clipboard
rx_method_channel: ^0.0.1 copied to clipboard

Reactive (Rx) wrapper for method channel.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:rx_method_channel/rx_method_channel.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final channel = RxMethodChannel(channelName: "test_channel");

  StreamSubscription? subs;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            MaterialButton(
              onPressed: () async {
                final value =
                    await channel.executeSingle(methodName: "mySingle").value;
                debugPrint(value);
              },
              child: const Center(
                child: Text("Execute Single"),
              ),
            ),
            MaterialButton(
              onPressed: () async {
                await channel
                    .executeCompletable(methodName: "myCompletable")
                    .value
                    .whenComplete(() => debugPrint("Completed"));
              },
              child: const Center(
                child: Text("Execute Completable"),
              ),
            ),
            MaterialButton(
              onPressed: () {
                subs?.cancel();
                subs = channel
                    .executeObservable(methodName: "myObservable")
                    .timeout(const Duration(seconds: 5))
                    .listen((event) {
                  debugPrint(event);
                });
              },
              child: const Center(
                child: Text("Execute Observable"),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
130
points
28
downloads

Publisher

unverified uploader

Weekly Downloads

Reactive (Rx) wrapper for method channel.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

async, flutter, plugin_platform_interface, rxdart

More

Packages that depend on rx_method_channel

Packages that implement rx_method_channel