# fluttercommunity/chewie architecture

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

- Interactive diagram: https://gitdiagram.com/fluttercommunity/chewie
- Repository: https://github.com/fluttercommunity/chewie

## Overview

##### Project Type and Purpose
- This is a Flutter plugin package (“chewie”) that wraps the low‐level `video_player` plugin to provide a friendly Material and Cupertino UI for video playback.
- The top‐level `lib/` folder contains the plugin’s Dart source; the `example/` folder contains a full Flutter app demonstrating Android, iOS and Web usage.

##### Key Architectural Components
A. Chewie Plugin Library (Dart)
- lib/chewie.dart – public export point
- lib/src/chewie_player.dart & lib/src/player_with_controls.dart – core widget compositions
- lib/src/material/* and lib/src/cupertino/* – UI widgets for different design systems
- lib/src/notifiers/player_notifier.dart – ViewModel/notifier implementing observer pattern
- lib/src/models/* – domain models (OptionItem, Subtitle, OptionsTranslation)
- lib/src/helpers/* – utility and adaptive control logic

B. Underlying Video Playback
- `video_player` plugin (external pub dependency)
- VideoPlayerController → bridges to platform channels

C. Platform‐Specific Layers
- Android native via MediaPlayer/ExoPlayer accessed by `video_player`
- iOS native via AVPlayer accessed by `video_player`
- Web via HTML5 <video> element

D. Example Application
- `example/` directory – Flutter app demonstrating plugin usage
- Platform subfolders: example/android, example/ios, example/web

E. CI/CD and Tooling
- .github/workflows/ci.yml & release.yml – GitHub Actions pipelines
- analysis_options.yaml, devtools_options.yaml – linting and development configs

##### Relationships and Data Flows
1. Example App (Flutter)
→ imports Chewie plugin
→ constructs VideoPlayerController (network or asset URL)
→ constructs ChewieController (wraps video controller + options)
→ instantiates Chewie widget in widget tree
2. Chewie Widget
→ uses ChewieController & PlayerNotifier to manage state
→ renders UI from material or cupertino submodules
→ binds UI controls (play, pause, seek, subtitles, options) to controller methods
3. ChewieController
→ delegates playback commands to VideoPlayerController
→ listens for playback state changes via notifiers
4. VideoPlayerController
→ issues platform channel calls to native Android/iOS/Web code
→ receives playback events (isPlaying, position, duration, buffering)
→ notifies ChewieController → updates UI

##### Architectural Patterns and Principles
- Plugin Pattern: clean separation between the UI wrapper (Chewie) and the core playback engine (`video_player`).
- MVC/MVVM‐like:
- Model = Subtitle, OptionItem
- ViewModel/Notifier = PlayerNotifier
- View = MaterialControls, CupertinoControls
- Observer Pattern: Notifiers broadcast playback state changes.
- Separation of Concerns: UI, business logic (controller), and platform code are isolated in different layers.
- Extensibility Points: additionalOptions callback, subtitleBuilder, optionsBuilder override.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Example App"
        direction TB
        ExMain["main.dart"]:::example
        App["app.dart"]:::example
        Theme["theme.dart"]:::example
        Sub_android["android/"]:::example_dir
        Sub_ios["ios/"]:::example_dir
        Sub_web["web/"]:::example_dir
    end

    subgraph "Chewie Plugin"
        direction TB
        API["chewie.dart"]:::plugin_entry
        ChewieCtrl["ChewieController"]:::controller

        subgraph "Widgets"
            direction TB
            Player["chewie_player.dart"]:::widget
            PlayerCtrl["player_with_controls.dart"]:::widget
        end

        subgraph "UI - Material"
            direction TB
            MatControls["material_controls.dart"]:::ui
            MatDesktop["material_desktop_controls.dart"]:::ui
            MatBar["material_progress_bar.dart"]:::ui
            ColorCompat["color_compat_extensions.dart"]:::ui
            OptionsDialog["options_dialog.dart"]:::ui
            SpeedDialog["playback_speed_dialog.dart"]:::ui
        end

        subgraph "UI - Cupertino"
            direction TB
            CupertinoControls["cupertino_controls.dart"]:::ui
            CupertinoBar["cupertino_progress_bar.dart"]:::ui
            CupertinoOptions["cupertino_options_dialog.dart"]:::ui
        end

        subgraph "Notifiers/Models/Helpers"
            direction TB
            Notifier["player_notifier.dart"]:::logic
            NotifierIndex["index.dart"]:::logic
            OptionItem["option_item.dart"]:::model
            Translation["options_translation.dart"]:::model
            Subtitle["subtitle_model.dart"]:::model
            ModelsIndex["index.dart"]:::model
            Adaptive["adaptive_controls.dart"]:::helper
            Utils["utils.dart"]:::helper
        end
    end

    subgraph "video_player Plugin"
        direction TB
        VPController["VideoPlayerController"]:::external
    end

    subgraph "Platform Native"
        direction TB
        Android["Android (MediaPlayer/ExoPlayer)"]:::native
        iOS["iOS (AVPlayer)"]:::native
        Web["Web (HTML5 video)"]:::native
    end

    ExMain -->|"imports"| API
    ExMain -->|"constructs"| ChewieCtrl
    ExMain -->|"uses"| VPController

    API -->|"initializes"| ChewieCtrl
    ChewieCtrl -->|"delegates play()/pause()"| VPController
    VPController -->|"platform channel calls"| Android
    VPController -->|"platform channel calls"| iOS
    VPController -->|"platform channel calls"| Web

    Android -->|"playback events"| VPController
    iOS -->|"playback events"| VPController
    Web -->|"playback events"| VPController

    VPController -->|"notifies"| Notifier
    Notifier -->|"updates UI"| Player
    Notifier -->|"updates UI"| PlayerCtrl

    Player -->|"renders"| MatControls
    Player -->|"renders"| CupertinoControls
    PlayerCtrl -->|"renders options"| OptionsDialog
    PlayerCtrl -->|"renders speed"| SpeedDialog
    Adaptive -->|"provides logic to"| MatControls
    Utils -->|"utility to"| Player

    classDef example fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef example_dir fill:#B3D4FF,stroke:#0366D6,color:#0366D6,stroke-dasharray: 2 2;
    classDef plugin_entry fill:#E6FFEA,stroke:#28A745,color:#22863A;
    classDef controller fill:#E6FFEA,stroke:#28A745,color:#22863A,stroke-width:2px;
    classDef widget fill:#EDFDE0,stroke:#28A745,color:#22863A;
    classDef ui fill:#EEFFEF,stroke:#28A745,color:#22863A;
    classDef logic fill:#F0FFF4,stroke:#28A745,color:#22863A;
    classDef model fill:#F7FFF7,stroke:#28A745,color:#22863A;
    classDef helper fill:#E8FFE8,stroke:#28A745,color:#22863A;
    classDef external fill:#FFF5E6,stroke:#D99000,color:#A86000;
    classDef native fill:#F2F2F2,stroke:#6A737D,color:#6A737D;

    click API "https://github.com/fluttercommunity/chewie/blob/master/lib/chewie.dart"
    click Player "https://github.com/fluttercommunity/chewie/blob/master/lib/src/chewie_player.dart"
    click PlayerCtrl "https://github.com/fluttercommunity/chewie/blob/master/lib/src/player_with_controls.dart"
    click MatControls "https://github.com/fluttercommunity/chewie/blob/master/lib/src/material/material_controls.dart"
    click MatDesktop "https://github.com/fluttercommunity/chewie/blob/master/lib/src/material/material_desktop_controls.dart"
    click MatBar "https://github.com/fluttercommunity/chewie/blob/master/lib/src/material/material_progress_bar.dart"
    click ColorCompat "https://github.com/fluttercommunity/chewie/blob/master/lib/src/material/color_compat_extensions.dart"
    click OptionsDialog "https://github.com/fluttercommunity/chewie/blob/master/lib/src/material/widgets/options_dialog.dart"
    click SpeedDialog "https://github.com/fluttercommunity/chewie/blob/master/lib/src/material/widgets/playback_speed_dialog.dart"
    click CupertinoControls "https://github.com/fluttercommunity/chewie/blob/master/lib/src/cupertino/cupertino_controls.dart"
    click CupertinoBar "https://github.com/fluttercommunity/chewie/blob/master/lib/src/cupertino/cupertino_progress_bar.dart"
    click CupertinoOptions "https://github.com/fluttercommunity/chewie/blob/master/lib/src/cupertino/widgets/cupertino_options_dialog.dart"
    click Notifier "https://github.com/fluttercommunity/chewie/blob/master/lib/src/notifiers/player_notifier.dart"
    click NotifierIndex "https://github.com/fluttercommunity/chewie/blob/master/lib/src/notifiers/index.dart"
    click OptionItem "https://github.com/fluttercommunity/chewie/blob/master/lib/src/models/option_item.dart"
    click Translation "https://github.com/fluttercommunity/chewie/blob/master/lib/src/models/options_translation.dart"
    click Subtitle "https://github.com/fluttercommunity/chewie/blob/master/lib/src/models/subtitle_model.dart"
    click ModelsIndex "https://github.com/fluttercommunity/chewie/blob/master/lib/src/models/index.dart"
    click Adaptive "https://github.com/fluttercommunity/chewie/blob/master/lib/src/helpers/adaptive_controls.dart"
    click Utils "https://github.com/fluttercommunity/chewie/blob/master/lib/src/helpers/utils.dart"
    click ExMain "https://github.com/fluttercommunity/chewie/blob/master/example/lib/main.dart"
    click App "https://github.com/fluttercommunity/chewie/blob/master/example/lib/app/app.dart"
    click Theme "https://github.com/fluttercommunity/chewie/blob/master/example/lib/app/theme.dart"
    click Sub_android "https://github.com/fluttercommunity/chewie/tree/master/example/android/"
    click Sub_ios "https://github.com/fluttercommunity/chewie/tree/master/example/ios/"
    click Sub_web "https://github.com/fluttercommunity/chewie/tree/master/example/web/"
```
