|
| 1 | +part of 'create_headline_bloc.dart'; |
| 2 | + |
| 3 | +/// Represents the status of the create headline operation. |
| 4 | +enum CreateHeadlineStatus { |
| 5 | + /// Initial state, before any data is loaded. |
| 6 | + initial, |
| 7 | + |
| 8 | + /// Data is being loaded. |
| 9 | + loading, |
| 10 | + |
| 11 | + /// An operation completed successfully. |
| 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 [CreateHeadlineBloc]. |
| 22 | +final class CreateHeadlineState extends Equatable { |
| 23 | + const CreateHeadlineState({ |
| 24 | + this.status = CreateHeadlineStatus.initial, |
| 25 | + this.title = '', |
| 26 | + this.description = '', |
| 27 | + this.url = '', |
| 28 | + this.imageUrl = '', |
| 29 | + this.source, |
| 30 | + this.category, |
| 31 | + this.sources = const [], |
| 32 | + this.categories = const [], |
| 33 | + this.errorMessage, |
| 34 | + }); |
| 35 | + |
| 36 | + final CreateHeadlineStatus status; |
| 37 | + final String title; |
| 38 | + final String description; |
| 39 | + final String url; |
| 40 | + final String imageUrl; |
| 41 | + final Source? source; |
| 42 | + final Category? category; |
| 43 | + final List<Source> sources; |
| 44 | + final List<Category> categories; |
| 45 | + final String? errorMessage; |
| 46 | + |
| 47 | + /// Returns true if the form is valid and can be submitted. |
| 48 | + bool get isFormValid => title.isNotEmpty; |
| 49 | + |
| 50 | + CreateHeadlineState copyWith({ |
| 51 | + CreateHeadlineStatus? status, |
| 52 | + String? title, |
| 53 | + String? description, |
| 54 | + String? url, |
| 55 | + String? imageUrl, |
| 56 | + ValueGetter<Source?>? source, |
| 57 | + ValueGetter<Category?>? category, |
| 58 | + List<Source>? sources, |
| 59 | + List<Category>? categories, |
| 60 | + String? errorMessage, |
| 61 | + }) { |
| 62 | + return CreateHeadlineState( |
| 63 | + status: status ?? this.status, |
| 64 | + title: title ?? this.title, |
| 65 | + description: description ?? this.description, |
| 66 | + url: url ?? this.url, |
| 67 | + imageUrl: imageUrl ?? this.imageUrl, |
| 68 | + source: source != null ? source() : this.source, |
| 69 | + category: category != null ? category() : this.category, |
| 70 | + sources: sources ?? this.sources, |
| 71 | + categories: categories ?? this.categories, |
| 72 | + errorMessage: errorMessage ?? this.errorMessage, |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + @override |
| 77 | + List<Object?> get props => [ |
| 78 | + status, |
| 79 | + title, |
| 80 | + description, |
| 81 | + url, |
| 82 | + imageUrl, |
| 83 | + source, |
| 84 | + category, |
| 85 | + sources, |
| 86 | + categories, |
| 87 | + errorMessage, |
| 88 | + ]; |
| 89 | +} |
| 90 | + |
0 commit comments