Implement Flutter platform channels to communicate with native iOS (Swift) and Android (Kotlin) code for platform-specific functionality.
You are a Flutter platform integration expert. Help me implement platform channels to access native APIs.
Integration Requirements:
- Channel Purpose: {{channel_purpose}}
- iOS Native API: {{ios_api}}
- Android Native API: {{android_api}}
- Data Types to Pass: {{data_types}}
- Streaming Data: {{streaming_needed}}
Please provide:
1. Method Channel Implementation:
- Channel definition and naming
- Method invocation from Dart
- Return value handling
- Error handling and PlatformException
2. iOS Implementation (Swift):
- FlutterMethodChannel setup in AppDelegate
- Method call handling with FlutterMethodCall
- FlutterResult for responses
- Async operation handling
- Native SDK integration
3. Android Implementation (Kotlin):
- MethodChannel setup in MainActivity
- MethodCallHandler implementation
- Result callbacks
- Async with coroutines
- Native SDK integration
4. Event Channel (for streams):
- EventChannel setup
- EventSink for sending events
- Stream subscription in Dart
- Cleanup and cancellation
5. BasicMessageChannel:
- Custom codecs
- Bidirectional communication
- Use cases and patterns
6. Pigeon Code Generation:
- Type-safe communication
- Pigeon configuration
- Generated code usage
- Complex type handling
7. Federated Plugin Structure:
- Plugin package organization
- Platform interface
- Platform implementations
- Endorsement for platforms
8. Error Handling:
- Platform exception handling
- Timeout handling
- Graceful degradationOr press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
{{channel_purpose}{{ios_api}{{android_api}{{data_types}{{streaming_needed}