platform_object_channel 1.0.1 copy "platform_object_channel: ^1.0.1" to clipboard
platform_object_channel: ^1.0.1 copied to clipboard

A Flutter plugin for create channel for platform object instance and dart object instance

example/lib/main.dart

import 'dart:io';

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

import 'package:platform_object_channel/platform_object_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> {
  dynamic _methodResult = 'Unknown';
  dynamic _streamMethodResult = 'Unknown';

  @override
  void initState() {
    super.initState();
final platformObjectInstance = PlatformObjectChannel(Platform.isAndroid ? "com.example.example.TestObject" : "TestObject", "arguments");
platformObjectInstance.setPlatformObjectMethodCallHandler(
  (method, arguments) async {
    if (method == "sayHi") {
      return "reply from flutter";
    }
  },
);
Future(() async {
  _methodResult = await platformObjectInstance.invokeMethod("sayHi", "im flutter");
});
Future(() async {
  await for (var element in platformObjectInstance.invokeMethodStream("sayHi_10", "im flutter, 10")) {
    setState(() {
      _streamMethodResult = element;
    });
  }
});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: [
            Text("method result: $_methodResult"),
            Text("stream method result: $_streamMethodResult"),
          ],
        ),
      ),
    );
  }
}
1
likes
140
points
85
downloads

Publisher

verified publisherybz.im

Weekly Downloads

A Flutter plugin for create channel for platform object instance and dart object instance

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, platform_object_channel_android, platform_object_channel_foundation, platform_object_channel_interface

More

Packages that depend on platform_object_channel