Creating an Entity

Let's create Entity 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 Use Cases powered by Bloc Cubits, it will either need to extend the Equatable class or integrate with the EquatableMixin class to improve the efficiency of BLoC by only emitting new states if and only if there are changes to the entity.

The equatable package is already made available by the codenic_bloc_use_case package.

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];
}

Last updated