# bytepark/auto_orientation architecture

> Architecture diagram of the GitHub repository bytepark/auto_orientation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bytepark/auto_orientation
- Repository: https://github.com/bytepark/auto_orientation

## Overview

##### Project Type Analysis
This is a Flutter plugin project that provides cross-platform (iOS and Android) functionality for programmatic screen orientation control. The project follows the standard Flutter plugin architecture with platform-specific implementations.

##### Main Components

A. Flutter Layer:
- Core Plugin Interface (`lib/auto_orientation.dart`)
- Public API Methods (landscapeLeftMode, portraitUpMode, etc.)

B. Platform-Specific Implementations:
- iOS Implementation (Swift)
- Android Implementation (Java)

C. Platform Channels:
- Method Channel for communication between Flutter and native code

- Blue: Flutter/Dart components
- Green: Android components
- Gray: iOS components
- Yellow: Platform channels
- Purple: Device system APIs

##### Top Layer (Application Layer)
- Flutter application using the plugin
- To the Plugin's Public API

##### Middle Layer (Plugin Interface)
- Main AutoOrientation class
- Available orientation methods
- Platform Channel communication

##### Bottom Layer (Platform-Specific)
- Split into iOS and Android implementations
- Connection to respective system orientation APIs

##### Key Relationships to Highlight

a. Method Flow:
- Flutter API calls → Platform Channel → Native Implementation
- Native Implementation → System Orientation API
- System Changes → Native Implementation → Platform Channel → Flutter

b. Dependencies:
- Flutter Framework
- Android Activity/Context
- iOS UIDevice Orientation

##### Implementation Details

**[AutoOrientation (Dart API)]**
- ↓
**[Platform Channel]**
- ↓
**[Platform Implementations]**
- [Android Implementation]
- [Activity Orientation Control]
- [iOS Implementation]
- [UIDevice Orientation Control]

##### Additional Elements

- A note section explaining the handling of SystemChrome.setPreferredOrientations
- Version compatibility information
- Error handling flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        App["Flutter Application"]:::flutter
        Example["Example Implementation"]:::flutter
    end

    subgraph "Plugin Interface Layer"
        AutoOrientation["AutoOrientation Plugin Interface"]:::flutter
        Methods["Orientation Control Methods<br/>- landscapeLeftMode()<br/>- portraitUpMode()<br/>- portraitAutoMode()<br/>- landscapeAutoMode()"]:::flutter
    end

    subgraph "Platform Channel Layer"
        Channel["Method Channel<br/>'auto_orientation'"]:::channel
    end

    subgraph "Platform-Specific Layer"
        direction TB
        subgraph "iOS Implementation"
            direction TB
            iOSPlugin["AutoOrientationPlugin.swift"]:::ios
            iOSConfig["Platform Configuration<br/>(Podspec)"]:::ios
            iOSSystem["UIDevice Orientation<br/>Control"]:::ios
        end

        subgraph "Android Implementation"
            direction TB
            AndroidPlugin["AutoOrientationPlugin.java"]:::android
            AndroidConfig["Platform Configuration<br/>(Gradle)"]:::android
            AndroidManifest["Android Manifest"]:::android
            AndroidSystem["Activity Orientation<br/>Control"]:::android
        end
    end

    App --> Example
    Example --> AutoOrientation
    AutoOrientation --> Methods
    Methods --> Channel
    Channel --> iOSPlugin
    Channel --> AndroidPlugin
    iOSPlugin --> iOSSystem
    AndroidPlugin --> AndroidSystem
    iOSPlugin --- iOSConfig
    AndroidPlugin --- AndroidConfig
    AndroidPlugin --- AndroidManifest

    %% Click Events
    click AutoOrientation "https://github.com/bytepark/auto_orientation/blob/master/lib/auto_orientation.dart"
    click iOSPlugin "https://github.com/bytepark/auto_orientation/blob/master/ios/Classes/AutoOrientationPlugin.swift"
    click AndroidPlugin "https://github.com/bytepark/auto_orientation/blob/master/android/src/main/java/de/bytepark/autoorientation/AutoOrientationPlugin.java"
    click Example "https://github.com/bytepark/auto_orientation/blob/master/example/lib/main.dart"
    click iOSConfig "https://github.com/bytepark/auto_orientation/blob/master/ios/auto_orientation.podspec"
    click AndroidConfig "https://github.com/bytepark/auto_orientation/blob/master/android/build.gradle"
    click AndroidManifest "https://github.com/bytepark/auto_orientation/blob/master/android/src/main/AndroidManifest.xml"

    %% Styles
    classDef flutter fill:#2196F3,stroke:#1565C0,color:white
    classDef android fill:#4CAF50,stroke:#388E3C,color:white
    classDef ios fill:#9E9E9E,stroke:#616161,color:white
    classDef channel fill:#FFC107,stroke:#FFA000,color:black

    %% Legend
    subgraph Legend
        Flutter["Flutter Components"]:::flutter
        Android["Android Components"]:::android
        iOS["iOS Components"]:::ios
        Channel["Platform Channel"]:::channel
    end
```
