Menu

Core Packages

Relevant source files

The Flutter Mobile Project Template includes a collection of foundational packages that provide essential functionality for the application. These core packages serve as the building blocks for feature development, ensuring a consistent architecture and separation of concerns.

Core packages are located in the packages/cores/ directory and provide fundamental capabilities such as data access, UI components, design system definitions, and model classes. They are designed to be reusable across features and applications within the project.

Core Package Overview

The template includes five primary core packages, each with a specific role in the application architecture:

Sources: packages/cores/core/pubspec.yaml packages/cores/data/pubspec.yaml packages/cores/designsystem/pubspec.yaml packages/cores/model/pubspec.yaml packages/cores/ui/pubspec.yaml

Package Dependencies

The following diagram illustrates how core packages relate to each other and how they're used by feature packages and applications:

Sources: apps/app/pubspec.yaml apps/catalog/pubspec.yaml packages/features/debug_mode/pubspec.yaml packages/features/setting/pubspec.yaml packages/features/force_update/pubspec.yaml packages/features/maintain/pubspec.yaml packages/cores/data/pubspec.yaml packages/cores/ui/pubspec.yaml

Core Package Details

cores_core

The cores_core package provides fundamental utilities and core functionality for the application.

Key Responsibilities:

  • Application logging through simple_logger
  • Core Riverpod providers
  • Common extensions and utilities
  • Base model interfaces and definitions

Main Components:

  • BuildConfig - Interface for application build configuration
  • Enum extensions (EnumByName) for safer enum handling
  • Riverpod providers for application-wide dependencies

Sources: packages/cores/core/pubspec.yaml packages/cores/core/lib/extension.dart packages/cores/core/lib/src/extension/enum.dart apps/app/lib/app_build_config.dart

cores_data

The cores_data package manages data access and persistence throughout the application.

Key Responsibilities:

  • Network communication using Dio
  • Local storage via SharedPreferences
  • Repository implementations for data access

Main Components:

  • sharedPreferencesProvider - Riverpod provider for SharedPreferences
  • Network clients for API communication
  • Repository implementation for data sources

Sources: packages/cores/data/pubspec.yaml apps/app/lib/app_initializer.dart45-50

cores_model

The cores_model package defines the data structures used throughout the application.

Key Responsibilities:

  • Define domain entities and data transfer objects
  • Provide immutable data models using Freezed

Dependencies:

  • This package has minimal dependencies (only Freezed) to avoid circular dependencies
  • It is meant to be imported by many other packages

Sources: packages/cores/model/pubspec.yaml

cores_designsystem

The cores_designsystem package defines the visual design language of the application.

Key Responsibilities:

  • Theme definitions
  • Color schemes
  • Typography
  • Asset management

Main Components:

  • Theme extensions for custom theme properties
  • Generated assets access

Sources: packages/cores/designsystem/pubspec.yaml

cores_ui

The cores_ui package provides reusable UI components built on top of the design system.

Key Responsibilities:

  • Reusable UI widgets
  • Common layout patterns
  • Localization support

Dependencies:

  • Depends on cores_designsystem for styling
  • Depends on cores_model for data structures used in UI

Sources: packages/cores/ui/pubspec.yaml

Application Initialization

Core packages play a key role in the application initialization process. The AppInitializer uses these core packages to set up the application environment.

Sources: apps/app/lib/app_initializer.dart

Usage Example

Here's an example of how the application initializes core packages and makes them available:

  1. The application creates an instance of AppBuildConfig implementing the BuildConfig interface from cores_core
  2. It initializes SharedPreferences which is provided through cores_data
  3. These instances are provided through Riverpod providers to be used throughout the application
AppInitializer._initializeProviders()
  ↓
  Creates provider overrides for:
    - buildConfigProvider (from cores_core)
    - sharedPreferencesProvider (from cores_data)
  ↓
  These providers are used by feature packages and the main app

Sources: apps/app/lib/app_initializer.dart24-52 apps/app/lib/app_build_config.dart

Extending Core Packages

When developing new features, follow these guidelines for interacting with core packages:

  1. Import only the core packages you need
  2. Respect the dependency hierarchy to avoid circular dependencies
  3. Feature-specific models should extend base models from cores_model
  4. UI components should follow the design system provided by cores_designsystem
  5. Data access should use the patterns established in cores_data

For specific information about implementing features using these core packages, see Feature Packages.

For details about the data layer implementation, see Data Layer.

For information about UI components, see UI Components.