|
| 1 | +part of 'create_category_bloc.dart'; |
| 2 | + |
| 3 | +/// Represents the status of the create category operation. |
| 4 | +enum CreateCategoryStatus { |
| 5 | + /// Initial state. |
| 6 | + initial, |
| 7 | + |
| 8 | + /// The form is being submitted. |
| 9 | + submitting, |
| 10 | + |
| 11 | + /// The operation completed successfully. |
| 12 | + success, |
| 13 | + |
| 14 | + /// An error occurred. |
| 15 | + failure, |
| 16 | +} |
| 17 | + |
| 18 | +/// The state for the [CreateCategoryBloc]. |
| 19 | +final class CreateCategoryState extends Equatable { |
| 20 | + /// {@macro create_category_state} |
| 21 | + const CreateCategoryState({ |
| 22 | + this.status = CreateCategoryStatus.initial, |
| 23 | + this.name = '', |
| 24 | + this.description = '', |
| 25 | + this.iconUrl = '', |
| 26 | + this.errorMessage, |
| 27 | + }); |
| 28 | + |
| 29 | + final CreateCategoryStatus status; |
| 30 | + final String name; |
| 31 | + final String description; |
| 32 | + final String iconUrl; |
| 33 | + final String? errorMessage; |
| 34 | + |
| 35 | + /// Returns true if the form is valid and can be submitted. |
| 36 | + /// Based on the Category model, only the name is required. |
| 37 | + bool get isFormValid => name.isNotEmpty; |
| 38 | + |
| 39 | + CreateCategoryState copyWith({ |
| 40 | + CreateCategoryStatus? status, |
| 41 | + String? name, |
| 42 | + String? description, |
| 43 | + String? iconUrl, |
| 44 | + String? errorMessage, |
| 45 | + }) { |
| 46 | + return CreateCategoryState( |
| 47 | + status: status ?? this.status, |
| 48 | + name: name ?? this.name, |
| 49 | + description: description ?? this.description, |
| 50 | + iconUrl: iconUrl ?? this.iconUrl, |
| 51 | + errorMessage: errorMessage, |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + @override |
| 56 | + List<Object?> get props => [status, name, description, iconUrl, errorMessage]; |
| 57 | +} |
0 commit comments