How fluttercommunity/chewie works
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.