flutter_platform_channels_plus 0.0.1
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 #
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 #
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- 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 #
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: Contact Developer
Made with โค๏ธ by Dhia Bechattaoui