How iamageo/flutter_mvvm_template works
Main Components
• Mobile Platforms: Although the primary focus is on the Flutter code under lib, include separate blocks (or notes) for the Android and iOS configurations. This shows that while the UI and business logic are cross-platform, build configurations and platform-specific settings are managed in dedicated directories.
• UI Layer:
• Located in the lib/ui directory with subdirectories organized by functionality (e.g., get and post). This layer contains the visual screens.
• Router:
• Found under lib/router, which centralizes screen definitions, routes, and navigation bindings using GetX.
• ViewModel / Controller Layer:
• Within lib/ui/controller and the GetX bindings in lib/ui/get/binding and lib/ui/post/binding. This layer implements the MVVM pattern by binding UI components to data streams via GetX.
• Repository & Data Access Layer:
• Found under lib/remote/repository, where the abstraction layer between the data sources (APIs) and the application resides. This layer ensures separation of concerns.
• API Client and Data Models:
• lib/remote/api holds components like API endpoints and HTTP manager for making network calls.
• lib/remote/model and lib/remote/response include the data models (with generated helpers from Freezed and json_serializable) and response handlers.
• External Libraries / Frameworks:
• GetX is used for state management, dependency injection, and navigation.
• Freezed and json_annotation handle data immutability and JSON conversion.
Relationships and Interactions
• Data flows back from the API response (processed by the corresponding response/model classes) to the Repository and then gets passed to the ViewModels which update the UI.
Architectural Patterns and Design Principles
• MVVM Pattern: Clearly separate out Model (data models and API response handling), View (UI screens), and ViewModel (controllers managing business logic and state).
• Repository Pattern: Abstract data sourcing by encapsulating API calls and local data (if applicable) so that the rest of the app is decoupled from data access logic.
• Code Generation Tools: Freezed (for immutable models) and json_annotation together with json_serializable are key parts of the Model layer.