How aloisdeniel/flutter_device_preview works
Project type and purpose
• This is a multi‐package Flutter/Dart monorepo hosting three related libraries (device_frame, device_preview, devtools_device_preview), plus a plugins folder and documentation site.
• The primary package (described in the README) is device_preview: a Flutter widget library that simulates various mobile and desktop devices, orientations, locales, themes, and hosts a plugin system (screenshots, file explorer, etc.).
High-level file-structure/architecture analysis
• Top-level packages
• device_frame – a Dart package containing data and drawing logic for device frames (Android, iOS, generic, Linux, macOS, Windows).
• device_preview – the core Flutter package providing the UI “shell” around your app to simulate devices.
• devtools_device_preview – a package that embeds Device Preview into Flutter DevTools.
• plugins/device_preview_screenshot – example of a Device Preview plugin handling screenshot capture.
• docs – static website content generated from the packages’ markdown documentation.
• Common pattern inside each package
• lib/src – package code, split into subfolders by concern (e.g., state, storage, views, utilities).
• example – a Flutter host app demonstrating how to integrate the package on Android, iOS, Web, macOS, Linux, Windows.
• pubspec.yaml – Dart/Flutter package configuration.
• test – unit or golden tests.
Core device_preview package component breakdown
a. Entry-point
• device_preview.dart – exports public API, including the DevicePreview widget.
b. UI Layer (Presentation)
• lib/src/views – Flutter widgets rendering the device preview shell, tool panel (sections: device, locale, settings, accessibility…), small/large views, theme toggles.
c. State Management
• lib/src/state – immutable state (freezed data classes), a Store class driving current device, orientation, locale, theme, and triggers updates.
d. Persistence (Storage Layer)
• lib/src/storage – abstract Storage interface, with implementations for file‐based and in‐memory (mock) on I/O and Web, and preferences backend (SharedPreferences, Web localStorage).
e. Utilities
• lib/src/utilities – media‐query observer, screenshot helpers, JSON converters, assertion helpers.
f. Plugins System
• DevicePreview exposes extension points: plugins register panels or actions (e.g., screenshot, file explorer).
g. Dependencies
• Depends on Flutter framework, provider or built_value-style libs (freezed), JSON serialization (json_serializable), and device_frame for frame drawing.
Relationships and data flow
• DevicePreview widget (Presentation)
→ reads from State Store
→ renders Views (tool panels, device canvas)
→ when user interacts (e.g., change orientation, theme, plugin action), dispatches actions to State Store
→ State Store updates state, notifies Views
→ State Store persists new state via Storage Layer
→ Utilities (media query observer) pick up environment changes, feed back into store
• device_frame package is imported by device_preview to supply Frame and Screen geometry & drawing logic.
Architectural patterns & design principles
• Layered architecture: Presentation (views) → Application state → Persistence (storage)
• Unidirectional data flow: UI events → State store → View updates
• Modular package structure: each package encapsulates its concern with examples
• Plugin extensibility: design a plugin API (register panels, actions) so third‐party plugins can hook into the tool panel