|
| 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