Skip to content

Commit

Permalink
form: add const / reorder constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
marfavi committed Feb 7, 2024
1 parent 22ebb57 commit 7ebc1e8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/src/shared/form/bloc/form_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:fpdart/fpdart.dart';
part 'form_event.dart';
part 'form_state.dart';

// FIXME: Utilise TaskEither for async validation
class FormBloc extends Bloc<FormEvent, FormState> {
FormBloc({required this.validators, required this.debounce})
: super(const FormState()) {
Expand Down Expand Up @@ -44,7 +45,7 @@ class FormBloc extends Bloc<FormEvent, FormState> {
);

on<FormToggleErrorDisplay>((event, emit) {
emit(state.copyWith(shouldDisplayError: event.displayError));
emit(state.copyWith(shouldDisplayError: event.showError));

Check warning on line 48 in lib/src/shared/form/bloc/form_bloc.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/shared/form/bloc/form_bloc.dart#L48

Added line #L48 was not covered by tests
});
}

Expand Down
14 changes: 9 additions & 5 deletions lib/src/shared/form/bloc/form_event.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
part of 'form_bloc.dart';

sealed class FormEvent extends Equatable {}
sealed class FormEvent extends Equatable {
const FormEvent();
}

/// The form wants to validate itself and should show a loading indicator.
class FormValidateRequested extends FormEvent {
const FormValidateRequested();

@override
List<Object?> get props => [];
}
Expand All @@ -13,7 +17,7 @@ class FormValidateRequested extends FormEvent {
/// This event is separated from [FormValidateRequested]
/// as this event can be debounced.
class FormValidateStarted extends FormEvent {
FormValidateStarted({required this.input});
const FormValidateStarted({required this.input});

Check warning on line 20 in lib/src/shared/form/bloc/form_event.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/shared/form/bloc/form_event.dart#L20

Added line #L20 was not covered by tests
final String input;

@override
Expand All @@ -23,9 +27,9 @@ class FormValidateStarted extends FormEvent {
/// The form should either enable/disable displaying
/// the error message (if there is an error).
class FormToggleErrorDisplay extends FormEvent {
FormToggleErrorDisplay({required this.displayError});
final bool displayError;
const FormToggleErrorDisplay({required this.showError});
final bool showError;

@override
List<Object?> get props => [displayError];
List<Object?> get props => [showError];

Check warning on line 34 in lib/src/shared/form/bloc/form_event.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/shared/form/bloc/form_event.dart#L34

Added line #L34 was not covered by tests
}
6 changes: 4 additions & 2 deletions lib/src/shared/form/widgets/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ class FormBase extends StatelessWidget {
inputValidators: inputValidators,
onChanged: (input) {
if (!state.loading) {
context.read<FormBloc>().add(FormValidateRequested());
context
.read<FormBloc>()
.add(const FormValidateRequested());

Check warning on line 96 in lib/src/shared/form/widgets/form.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/shared/form/widgets/form.dart#L95-L96

Added lines #L95 - L96 were not covered by tests
}
context
.read<FormBloc>()
Expand All @@ -100,7 +102,7 @@ class FormBase extends StatelessWidget {
onEditingComplete: () {
context
.read<FormBloc>()
.add(FormToggleErrorDisplay(displayError: true));
.add(const FormToggleErrorDisplay(showError: true));

Check warning on line 105 in lib/src/shared/form/widgets/form.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/shared/form/widgets/form.dart#L104-L105

Added lines #L104 - L105 were not covered by tests
if (state.canSubmit) {
onSubmit(state.text);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/voucher_code/bloc/voucher_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ class VoucherLoading extends VoucherState {

// FIXME: Make error states a common class?
class VoucherError extends VoucherState {
final String error;

const VoucherError(this.error);
final String error;

@override
List<Object> get props => [error];
Expand Down

0 comments on commit 7ebc1e8

Please sign in to comment.