E-Core

Data

Repositories and data sources for E-Core

Data Layer

The Data package provides the data layer implementation with repository pattern and offline-first support.

Overview

e_core_data includes:

  • Repository Pattern - Clean data access abstraction
  • Data Sources - Remote and local data source interfaces
  • Caching - Built-in caching strategies
  • Offline Support - Offline-first data synchronization

Installation

dependencies:
  e_core_data: ^1.0.0

Key Patterns

Repository Implementation

class UsersRepositoryImpl implements UsersRepository {
  final UsersRemoteDataSource _remote;
  final UsersLocalDataSource _local;

  UsersRepositoryImpl(this._remote, this._local);

  @override
  Future<List<User>> getUsers() async {
    try {
      final users = await _remote.fetchUsers();
      await _local.cacheUsers(users);
      return users;
    } catch (e) {
      return _local.getCachedUsers();
    }
  }
}

Data Source Interfaces

abstract class UsersRemoteDataSource {
  Future<List<UserDto>> fetchUsers();
}

abstract class UsersLocalDataSource {
  Future<List<User>> getCachedUsers();
  Future<void> cacheUsers(List<User> users);
}

Learn More

On this page