|
| 1 | +part of 'create_source_bloc.dart'; |
| 2 | + |
| 3 | +/// Represents the status of the create source operation. |
| 4 | +enum CreateSourceStatus { |
| 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 [CreateSourceBloc]. |
| 22 | +final class CreateSourceState extends Equatable { |
| 23 | + /// {@macro create_source_state} |
| 24 | + const CreateSourceState({ |
| 25 | + this.status = CreateSourceStatus.initial, |
| 26 | + this.name = '', |
| 27 | + this.description = '', |
| 28 | + this.url = '', |
| 29 | + this.sourceType, |
| 30 | + this.language = '', |
| 31 | + this.headquarters, |
| 32 | + this.countries = const [], |
| 33 | + this.errorMessage, |
| 34 | + }); |
| 35 | + |
| 36 | + final CreateSourceStatus status; |
| 37 | + final String name; |
| 38 | + final String description; |
| 39 | + final String url; |
| 40 | + final SourceType? sourceType; |
| 41 | + final String language; |
| 42 | + final Country? headquarters; |
| 43 | + final List<Country> countries; |
| 44 | + final String? errorMessage; |
| 45 | + |
| 46 | + /// Returns true if the form is valid and can be submitted. |
| 47 | + bool get isFormValid => name.isNotEmpty; |
| 48 | + |
| 49 | + CreateSourceState copyWith({ |
| 50 | + CreateSourceStatus? status, |
| 51 | + String? name, |
| 52 | + String? description, |
| 53 | + String? url, |
| 54 | + ValueGetter<SourceType?>? sourceType, |
| 55 | + String? language, |
| 56 | + ValueGetter<Country?>? headquarters, |
| 57 | + List<Country>? countries, |
| 58 | + String? errorMessage, |
| 59 | + }) { |
| 60 | + return CreateSourceState( |
| 61 | + status: status ?? this.status, |
| 62 | + name: name ?? this.name, |
| 63 | + description: description ?? this.description, |
| 64 | + url: url ?? this.url, |
| 65 | + sourceType: sourceType != null ? sourceType() : this.sourceType, |
| 66 | + language: language ?? this.language, |
| 67 | + headquarters: headquarters != null ? headquarters() : this.headquarters, |
| 68 | + countries: countries ?? this.countries, |
| 69 | + errorMessage: errorMessage, |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + @override |
| 74 | + List<Object?> get props => [ |
| 75 | + status, |
| 76 | + name, |
| 77 | + description, |
| 78 | + url, |
| 79 | + sourceType, |
| 80 | + language, |
| 81 | + headquarters, |
| 82 | + countries, |
| 83 | + errorMessage, |
| 84 | + ]; |
| 85 | +} |
0 commit comments