This Flutter application demonstrates bi-directional communication between Flutter and native iOS code, implementing a data communication layer that interfaces between iOS and Flutter.
Find a file
Danial M ab01ac3184 Add architecture documentation and troubleshooting guide
- Introduced ARCHITECTURE.md to detail the iOS-Flutter communication architecture, including system components and design patterns.
- Enhanced README.md with an architecture overview and communication flow for better understanding of the project structure.
- Added TROUBLESHOOTING.md to provide solutions for common issues encountered during development, covering connection, data, integration, and performance problems.
2025-03-23 05:17:33 +03:30
.vscode Add initial project structure and files for iOS-Flutter Communication Prototype 2025-03-23 04:59:09 +03:30
assets Add initial project structure and files for iOS-Flutter Communication Prototype 2025-03-23 04:59:09 +03:30
ios Add initial project structure and files for iOS-Flutter Communication Prototype 2025-03-23 04:59:09 +03:30
lib Add initial project structure and files for iOS-Flutter Communication Prototype 2025-03-23 04:59:09 +03:30
.gitignore Add initial project structure and files for iOS-Flutter Communication Prototype 2025-03-23 04:59:09 +03:30
.metadata Add initial project structure and files for iOS-Flutter Communication Prototype 2025-03-23 04:59:09 +03:30
analysis_options.yaml Add initial project structure and files for iOS-Flutter Communication Prototype 2025-03-23 04:59:09 +03:30
ARCHITECTURE.md Add architecture documentation and troubleshooting guide 2025-03-23 05:17:33 +03:30
demo-in-simulator.png Add demo image to README and update video link reference 2025-03-23 05:06:16 +03:30
devtools_options.yaml Add initial project structure and files for iOS-Flutter Communication Prototype 2025-03-23 04:59:09 +03:30
l10n.yaml Add initial project structure and files for iOS-Flutter Communication Prototype 2025-03-23 04:59:09 +03:30
pubspec.lock Add initial project structure and files for iOS-Flutter Communication Prototype 2025-03-23 04:59:09 +03:30
pubspec.yaml Add initial project structure and files for iOS-Flutter Communication Prototype 2025-03-23 04:59:09 +03:30
README.md Add architecture documentation and troubleshooting guide 2025-03-23 05:17:33 +03:30
TROUBLESHOOTING.md Add architecture documentation and troubleshooting guide 2025-03-23 05:17:33 +03:30

iOS-Flutter Communication Prototype

This Flutter application demonstrates bi-directional communication between Flutter and native iOS code, implementing a data communication layer that interfaces between iOS and Flutter.

Features

  • Sends commands from Flutter to native iOS code using method channels
  • Receives real-time data (random integers) generated on the iOS side via event channels
  • Demonstrates clean architecture with BLoC pattern for state management
  • Error handling for robust communication
  • Multilingual support (English and Japanese)
  • Modern UI with animations

Demo

Video Demonstration (YouTube Shorts)

[Watch Demo on YouTube](https://www.youtube.com/shorts/4Lap_HX_JbE)

👆 Click the image above to watch the short demo video showing the iOS-Flutter communication in action.

Direct Link : https://www.youtube.com/shorts/4Lap_HX_JbE

Architecture Overview

The project implements a clean architecture approach with the following components:

  1. Presentation Layer (Flutter UI)

    • Uses BLoC pattern for state management
    • Handles UI updates based on data received from iOS
  2. Communication Layer

    • Method Channels: For communicating from Flutter to iOS
    • Event Channels: For receiving streaming data from iOS to Flutter
  3. Native iOS Implementation

    • Swift implementation in AppDelegate
    • Random data generator simulating USB data reception
    • Timer-based data emission to demonstrate real-time communication

Design Patterns

  1. BLoC Pattern (Business Logic Component)

    • Separates business logic from UI
    • Provides a structured way to handle state management
    • Facilitates testing and code maintenance
  2. Singleton Pattern

    • Used for the method and event channels
    • Ensures a single point of access for platform communication
  3. Observer Pattern

    • Implemented via event channels and stream subscriptions
    • Allows for reactive updates when data is received from iOS
  4. Repository Pattern

    • Abstracts the data source from the business logic
    • Provides a clean API for the BLoC to interact with

Communication Flow

  1. Flutter to iOS:

    • Flutter UI triggers an action (start/stop data generation)
    • BLoC processes the event and invokes the method channel
    • iOS native code receives the method call and performs the requested action
  2. iOS to Flutter:

    • iOS generates random integers using a timer
    • Data is sent through the event channel
    • Flutter's event channel listener receives the data
    • BLoC processes the received data and updates the UI

Getting Started

Prerequisites

  • Flutter 3.0.0 or higher
  • Xcode 13.0 or higher (for iOS builds)
  • iOS 12.0+ device or simulator
  • CocoaPods for iOS dependency management

Installation

  1. Clone this repository
git clone <repository-url>
  1. Navigate to the project directory
cd ios_communication_prototype
  1. Install Flutter dependencies
flutter pub get
  1. Install iOS dependencies
cd ios && pod install && cd ..
  1. Run the application
flutter run -d iphone

Project Structure

lib/
├── main.dart                    # Application entry point
├── src/
│   ├── app_preferences/         # App preferences management
│   ├── bloc/                    # Business logic components
│   │   ├── ios_communication/   # iOS communication BLoC
│   │   │   ├── ios_communication_bloc.dart
│   │   │   └── ios_communication_response_model.dart
│   ├── core/                    # Core utilities and constants
│   ├── helpers/                 # Helper classes
│   ├── localization/            # Internationalization
│   ├── navigator/               # Navigation management
│   └── view/                    # UI components
│       ├── page/                # App pages
│       └── widget/              # Reusable widgets

Implementation Details

Flutter Side

  • Uses method channels (com.zanis.ios_communication/method) to send commands to iOS
  • Listens to event channels (com.zanis.ios_communication/event) to receive data from iOS
  • BLoC pattern handles state management and UI updates

iOS Native Side

  • Implements method channel handlers in Swift via AppDelegate
  • Creates a timer to simulate data generation (as a substitute for actual USB data)
  • Sends data to Flutter using event channels

Localization

The app supports both English and Japanese languages. The localization files are located in:

  • lib/src/localization/app_en.arb (English)
  • lib/src/localization/app_ja.arb (Japanese)

Note: After modifying any ARB files, run flutter gen-l10n to regenerate the localization files and make the changes available in the application.

Debugging and Troubleshooting

When troubleshooting communication issues:

  1. Connection Timeout: Check that method channels are properly set up and registered on both Flutter and iOS sides.

  2. Data Corruption: Verify that data serialization/deserialization is consistent between Flutter and iOS.

  3. Integration Failures: Ensure method channel names match exactly on both sides.

License

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