How hungps/flutter_starter works
Main Components
a. Platform-specific Shells & Configuration:
• Platforms: Android, iOS, web, desktop (Linux, macOS, Windows)
• Flavor Management: Different entry files (lib/main_dev.dart, lib/main_staging.dart, lib/main_production.dart) and flavor configurations (lib/flavors.dart, flavorizr.yaml) to manage environment-specific settings.
• Build Tools/Infrastructure: FVM configuration, Mason bricks (located under bricks/ and mason.yaml) for rapid code generation, and platform-specific directories that detail asset usage and build scripts.
b. Presentation Layer:
• Internationalization: Languages support with translations (lib/presenter/languages, translations in JSON files) and a script to generate translation keys.
c. Data Layer:
• Entities & Data Models: Under lib/data/entities, you have core models (for accounts, login parameters, etc.) with accompanying generated files.
• Repositories: e.g. the auth_repository defined in lib/data/repositories/auth_repository, managing the coordination between data sources.
• Data Sources: Separated into local (lib/data/sources/local) and network (lib/data/sources/network) layers, including integration with networking libraries (Dio is in use).
• Use Cases: Business logic like login and verifying login status is abstracted in lib/data/usecases.
d. Core & Cross-cutting Concerns:
• Core Logic: Common logic elements (e.g., exception handling in lib/core/exception.dart, common use cases in lib/core/use_case.dart).
• Dependency Injection: Setup in lib/di.dart and generated configuration in lib/di.config.dart to wire components.
• State Management: Bloc implementations for authentication and settings in lib/data/states, following the bloc pattern (auth_bloc, settings_bloc, etc.).
e. Auxiliary Services:
• Services such as OAuth token management (lib/services/oauth_token_manager) to manage external authentication tokens.
Relationships and Interactions
• UI Interaction Flow: The user interacts with the Presentation layer. Pages in the presenter dispatch events to blocs (e.g., login_bloc, splash_bloc) which then call use cases in the Data layer.
• Business Logic Flow: Use cases use repositories which abstract access to multiple data sources. Local and network sources feed data upstream, and exceptions are propagated via the core logic.
• Dependency Injection: DI (using lib/di files) is central to wiring up state management components, repositories, services, and use cases.
• Environment & Flavor Management: Different main entry points (dev, staging, production) and configurations allow the system to select the correct resources and endpoints based on the build flavor.
• Code Generation: The bricks and Mason CLI scripts support generating new modules (like bloc pages) and updating translation keys, ensuring consistency across the architecture.
Architectural Patterns and Technologies
• Bloc/State Management: Use of blocs to manage state transitions across authentication and settings workflows.
• MVVM/MVC or Clean Architecture: The separation of Presentation, Domain (use cases), and Data layers points to a Clean Architecture approach.
• Cross-Platform Design: Flutter structure supports multiple platforms with shared business logic, while platform-specific folders (android, ios, etc.) deal with native configurations.
• Internationalization: Integration of easy_localization to drive multi-language support.
• Dependency Injection: Use of DI to improve modularity and testability.