Codenic Clean Architecture
  • Introduction
  • The Clean Architecture
    • Presentation Layer
    • Domain Layer
    • Infrastructure Layer
  • Tutorial
    • Overview
    • Creating a Flutter Modular Project
      • Tips for Managing a Modular Project
    • Implementing the Domain Layer
      • Core Dependencies
      • Creating an Entity
      • Creating a Failure
      • Creating a Repository Interface
      • Creating Use Cases
        • CRUD Operations (Runner)
        • Data Streams (Watcher)
    • Implementing the Infrastructure Layer
      • External Dependencies
      • Creating a Data Model
      • Creating a Data Source
      • Implementing a Repository
    • Implementing the Presentation Layer
      • External Dependencies
      • Dependency Injection and Service Locator
      • Widgets
        • Snackbar Handler
        • Global Blocs Widget
        • Note Widgets
  • Packages
    • Codenic Bloc Use Case
      • Runner
      • Watcher
    • Codenic Logger
      • Usage
      • Example
      • Modifying the Logger
      • Integrating Firebase Crashlytics to the logger
    • Codenic Exception Converter
      • Failure Object
      • Exception Converter
      • Exception Converter Suite
      • Example
Powered by GitBook
On this page
  1. Tutorial
  2. Implementing the Domain Layer

Creating an Entity

PreviousCore DependenciesNextCreating a Failure

Last updated 2 years ago

Let's create for our note entry with the following properties: title, content, and last updated timestamp.

Since our Entity will flow between the Presentation and Infrastructure layers via , it will either need to extend the class or integrate with the class to improve the efficiency of BLoC by only emitting new states if and only if there are changes to the entity.

The is already made available by the .

Create a file called note_entry.dart in the note_app/modules/domain/lib/note/entities/ directory:

import 'package:domain/domain.dart';

/// {@template NoteEntry}
/// A model representing a note entry.
/// {@endtemplate}
class NoteEntry with EquatableMixin {
  /// {@macro NoteEntry}
  const NoteEntry({
    required this.id,
    required this.title,
    required this.content,
    required this.updatedAt,
  });

  /// The unique identifier of the note entry.
  final String id;

  /// The title of the note entry.
  final String title;

  /// The content of the note entry.
  final String content;

  /// The date and time when the note entry was last updated.
  final DateTime updatedAt;

  /// Creates a copy of the note entry with the given fields replaced with the
  /// new values.
  NoteEntry copyWith({
    String? id,
    String? title,
    String? content,
    DateTime? updatedAt,
  }) =>
      NoteEntry(
        id: id ?? this.id,
        title: title ?? this.title,
        content: content ?? this.content,
        updatedAt: updatedAt ?? this.updatedAt,
      );

  @override
  List<Object?> get props => [id, title, content, updatedAt];
}
Use Cases powered by Bloc Cubits
Equatable
EquatableMixin
equatable package
codenic_bloc_use_case package
Entity