Skip to content

Commit 7b4a99a

Browse files
committed
feat(content_management): Add EditCategoryState
- Defines EditCategoryStatus enum - Implements EditCategoryState class - Includes form validation logic
1 parent 0af84e1 commit 7b4a99a

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
part of 'edit_category_bloc.dart';
2+
3+
/// Represents the status of the edit category operation.
4+
enum EditCategoryStatus {
5+
/// Initial state, before any data is loaded.
6+
initial,
7+
8+
/// Data is being loaded.
9+
loading,
10+
11+
/// Data has been successfully loaded or an operation completed.
12+
success,
13+
14+
/// An error occurred.
15+
failure,
16+
17+
/// The form is being submitted.
18+
submitting,
19+
}
20+
21+
/// The state for the [EditCategoryBloc].
22+
final class EditCategoryState extends Equatable {
23+
const EditCategoryState({
24+
this.status = EditCategoryStatus.initial,
25+
this.initialCategory,
26+
this.name = '',
27+
this.description = '',
28+
this.iconUrl = '',
29+
this.errorMessage,
30+
});
31+
32+
final EditCategoryStatus status;
33+
final Category? initialCategory;
34+
final String name;
35+
final String description;
36+
final String iconUrl;
37+
final String? errorMessage;
38+
39+
/// Returns true if the form is valid and can be submitted.
40+
bool get isFormValid => name.isNotEmpty;
41+
42+
EditCategoryState copyWith({
43+
EditCategoryStatus? status,
44+
Category? initialCategory,
45+
String? name,
46+
String? description,
47+
String? iconUrl,
48+
String? errorMessage,
49+
}) {
50+
return EditCategoryState(
51+
status: status ?? this.status,
52+
initialCategory: initialCategory ?? this.initialCategory,
53+
name: name ?? this.name,
54+
description: description ?? this.description,
55+
iconUrl: iconUrl ?? this.iconUrl,
56+
errorMessage: errorMessage ?? this.errorMessage,
57+
);
58+
}
59+
60+
@override
61+
List<Object?> get props =>
62+
[status, initialCategory, name, description, iconUrl, errorMessage];
63+
}
64+

0 commit comments

Comments
 (0)