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

Simplified platform channel communication for Flutter with support for all 6 platforms (iOS, Android, Web, Windows, macOS, Linux) and WASM compatibility.

flutter_platform_channels_plus #

Pub Version Flutter Version Dart Version License

A Flutter plugin that provides simplified platform channel communication with support for all 6 platforms (iOS, Android, Web, Windows, macOS, Linux) and WASM compatibility.

โœจ Features #

  • ๐Ÿ”„ Method Channels: Simple method invocation between Flutter and native code
  • ๐Ÿ“ก Event Channels: Real-time communication with native platforms
  • ๐Ÿ’ฌ Basic Message Channels: Raw message passing with custom codecs
  • ๐Ÿ” Platform Detection: Runtime platform identification and capability checking
  • โšก Error Handling: Comprehensive error management with custom exceptions
  • ๐Ÿ›ก๏ธ Type Safety: Full null safety support and generic type handling
  • โš™๏ธ Configuration: Flexible configuration options for timeouts, retries, and logging
  • ๐ŸŒ WASM Support: WebAssembly compatibility for web platform

๐Ÿš€ Supported Platforms #

Platform Support Native Code WASM
iOS โœ… Full โœ… Yes โŒ No
Android โœ… Full โœ… Yes โŒ No
Web โœ… Full โŒ No โœ… Yes
Windows โœ… Full โœ… Yes โŒ No
macOS โœ… Full โœ… Yes โŒ No
Linux โœ… Full โœ… Yes โŒ No

๐Ÿ“ฆ Installation #

Add this dependency to your pubspec.yaml:

dependencies:
  flutter_platform_channels_plus: ^0.0.1

Then run:

flutter pub get

๐ŸŽฏ Quick Start #

Basic Usage #

import 'package:flutter_platform_channels_plus/flutter_platform_channels_plus.dart';

// Create a method channel
final channel = MethodChannelPlus('my_channel');

// Invoke a method
final result = await channel.invokeMethod('getData');
if (result.isSuccess) {
  print('Data: ${result.data}');
} else {
  print('Error: ${result.error}');
}

Event Channels #

// Create an event channel
final eventChannel = EventChannelPlus('sensor_data');

// Listen to events
eventChannel.receiveBroadcastStream().listen((event) {
  print('Received sensor data: $event');
});

Message Channels #

// Create a message channel for text
final messageChannel = BasicMessageChannelPlus.forText('chat');

// Send a message
await messageChannel.send('Hello, World!');

// Send and receive
final response = await messageChannel.sendAndReceive('ping');
print('Response: $response'); // Output: pong

๐Ÿ”ง Configuration #

Channel Configuration #

final config = ChannelConfig(
  timeout: Duration(seconds: 30),
  retryCount: 3,
  enableLogging: true,
);

final channel = MethodChannelPlus('my_channel', config: config);

Pre-configured Channels #

// High-frequency events (optimized for performance)
final sensorChannel = EventChannelPlus.forHighFrequency('sensors');

// Debug mode (with logging and longer timeouts)
final debugChannel = EventChannelPlus.forDebug('debug');

// Text-based communication
final textChannel = BasicMessageChannelPlus.forText('messages');

// Binary data communication
final binaryChannel = BasicMessageChannelPlus.forBinary('files');

๐Ÿ“š API Reference #

MethodChannelPlus #

The enhanced method channel with better error handling and configuration.

class MethodChannelPlus {
  // Basic method invocation
  Future<ChannelResult<dynamic>> invokeMethod(String method, [dynamic arguments]);
  
  // Strict method invocation (throws on error)
  Future<T> invokeMethodStrict<T>(String method, [dynamic arguments]);
  
  // Method invocation with retry logic
  Future<ChannelResult<dynamic>> invokeMethodWithRetry(String method, [dynamic arguments, int? maxRetries]);
  
  // Method invocation with timeout
  Future<ChannelResult<dynamic>> invokeMethodWithTimeout(String method, [dynamic arguments, Duration? timeout]);
}

EventChannelPlus #

Real-time communication channel for events and streams.

class EventChannelPlus {
  // Broadcast stream (multiple listeners)
  Stream<dynamic> receiveBroadcastStream([dynamic arguments]);
  
  // Single subscription stream
  Stream<dynamic> receiveStream([dynamic arguments]);
  
  // Send event to platform
  Future<ChannelResult<void>> sendEvent(dynamic event);
}

BasicMessageChannelPlus #

Raw message passing with custom codecs.

class BasicMessageChannelPlus<T> {
  // Send message
  Future<ChannelResult<void>> send(T message);
  
  // Send and receive
  Future<ChannelResult<T>> sendAndReceive(T message);
  
  // Set message handler
  Future<ChannelResult<void>> setMessageHandler(Future<T?> Function(T? message)? handler);
}

Platform Detection #

class PlatformDetector {
  // Current platform
  static PlatformType get currentPlatform;
  
  // Platform capabilities
  static bool get isWeb;
  static bool get isMobile;
  static bool get isDesktop;
  static bool get supportsNativeCode;
  static bool get supportsWasm;
  
  // Check specific capability
  static bool supportsCapability(String capability);
}

๐Ÿงช Testing #

Run the test suite:

flutter test

Run with coverage:

flutter test --coverage

๐Ÿ“– Examples #

Check out the example/ directory for complete usage examples:

  • Basic Example: Simple method channel usage
  • Event Example: Real-time event handling
  • Message Example: Custom message codecs
  • Platform Example: Platform detection and capabilities

๐Ÿ” Platform Analysis #

This plugin has been analyzed with:

  • โœ… Pana: Full score analysis
  • โœ… Flutter Analyze: Code quality checks
  • โœ… Dart Analysis: Language compliance
  • โœ… Dry Publish: Pre-publication validation

Target Score: 160/160 ๐ŸŽฏ

๐Ÿค Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup #

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

๐Ÿ“„ License #

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments #

  • Flutter team for the excellent platform channel architecture
  • The Dart community for continuous improvements
  • Contributors and users of this plugin

๐Ÿ“ž Support #


Made with โค๏ธ by Dhia Bechattaoui

1
likes
160
points
97
downloads

Publisher

verified publisherbechattaoui.dev

Weekly Downloads

Simplified platform channel communication for Flutter with support for all 6 platforms (iOS, Android, Web, Windows, macOS, Linux) and WASM compatibility.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_platform_channels_plus