From 13c55afe3c2f3e45a724f52eb62bc6a66118da41 Mon Sep 17 00:00:00 2001 From: efrilm Date: Thu, 18 Sep 2025 06:23:51 +0700 Subject: [PATCH] register bloc --- .../register_form/register_form_bloc.dart | 69 ++ .../register_form_bloc.freezed.dart | 944 ++++++++++++++++++ .../register_form/register_form_event.dart | 11 + .../register_form/register_form_state.dart | 20 + lib/injection.config.dart | 5 + 5 files changed, 1049 insertions(+) create mode 100644 lib/application/auth/register_form/register_form_bloc.dart create mode 100644 lib/application/auth/register_form/register_form_bloc.freezed.dart create mode 100644 lib/application/auth/register_form/register_form_event.dart create mode 100644 lib/application/auth/register_form/register_form_state.dart diff --git a/lib/application/auth/register_form/register_form_bloc.dart b/lib/application/auth/register_form/register_form_bloc.dart new file mode 100644 index 0000000..697a260 --- /dev/null +++ b/lib/application/auth/register_form/register_form_bloc.dart @@ -0,0 +1,69 @@ +import 'package:bloc/bloc.dart'; +import 'package:dartz/dartz.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:injectable/injectable.dart'; + +import '../../../domain/auth/auth.dart'; + +part 'register_form_event.dart'; +part 'register_form_state.dart'; +part 'register_form_bloc.freezed.dart'; + +@injectable +class RegisterFormBloc extends Bloc { + final IAuthRepository _repository; + RegisterFormBloc(this._repository) : super(RegisterFormState.initial()) { + on(_onRegisterFormEvent); + } + + Future _onRegisterFormEvent( + RegisterFormEvent event, + Emitter emit, + ) { + return event.map( + phoneNumberChanged: (e) async { + emit( + state.copyWith( + phoneNumber: e.phoneNumber, + failureOrRegisterOption: none(), + ), + ); + }, + nameChanged: (e) async { + emit(state.copyWith(name: e.name, failureOrRegisterOption: none())); + }, + birthDateChanged: (e) async { + emit( + state.copyWith( + birthDate: e.birthDate, + failureOrRegisterOption: none(), + ), + ); + }, + submitted: (e) async { + Either? failureOrRegister; + emit( + state.copyWith(isSubmitting: true, failureOrRegisterOption: none()), + ); + + final phoneNumberValid = state.phoneNumber.isNotEmpty; + final nameValid = state.name.isNotEmpty; + + if (phoneNumberValid && nameValid) { + failureOrRegister = await _repository.register( + phoneNumber: state.phoneNumber, + name: state.name, + birthDate: state.birthDate, + ); + emit( + state.copyWith( + isSubmitting: false, + failureOrRegisterOption: optionOf(failureOrRegister), + ), + ); + } + emit(state.copyWith(showErrorMessages: true, isSubmitting: false)); + }, + ); + } +} diff --git a/lib/application/auth/register_form/register_form_bloc.freezed.dart b/lib/application/auth/register_form/register_form_bloc.freezed.dart new file mode 100644 index 0000000..cbd87c8 --- /dev/null +++ b/lib/application/auth/register_form/register_form_bloc.freezed.dart @@ -0,0 +1,944 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'register_form_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models', +); + +/// @nodoc +mixin _$RegisterFormEvent { + @optionalTypeArgs + TResult when({ + required TResult Function(String phoneNumber) phoneNumberChanged, + required TResult Function(String name) nameChanged, + required TResult Function(DateTime birthDate) birthDateChanged, + required TResult Function() submitted, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String phoneNumber)? phoneNumberChanged, + TResult? Function(String name)? nameChanged, + TResult? Function(DateTime birthDate)? birthDateChanged, + TResult? Function()? submitted, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String phoneNumber)? phoneNumberChanged, + TResult Function(String name)? nameChanged, + TResult Function(DateTime birthDate)? birthDateChanged, + TResult Function()? submitted, + required TResult orElse(), + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_PhoneNumberChanged value) phoneNumberChanged, + required TResult Function(_NameChanged value) nameChanged, + required TResult Function(_BirthDateChanged value) birthDateChanged, + required TResult Function(_Submitted value) submitted, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_PhoneNumberChanged value)? phoneNumberChanged, + TResult? Function(_NameChanged value)? nameChanged, + TResult? Function(_BirthDateChanged value)? birthDateChanged, + TResult? Function(_Submitted value)? submitted, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_PhoneNumberChanged value)? phoneNumberChanged, + TResult Function(_NameChanged value)? nameChanged, + TResult Function(_BirthDateChanged value)? birthDateChanged, + TResult Function(_Submitted value)? submitted, + required TResult orElse(), + }) => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RegisterFormEventCopyWith<$Res> { + factory $RegisterFormEventCopyWith( + RegisterFormEvent value, + $Res Function(RegisterFormEvent) then, + ) = _$RegisterFormEventCopyWithImpl<$Res, RegisterFormEvent>; +} + +/// @nodoc +class _$RegisterFormEventCopyWithImpl<$Res, $Val extends RegisterFormEvent> + implements $RegisterFormEventCopyWith<$Res> { + _$RegisterFormEventCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of RegisterFormEvent + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc +abstract class _$$PhoneNumberChangedImplCopyWith<$Res> { + factory _$$PhoneNumberChangedImplCopyWith( + _$PhoneNumberChangedImpl value, + $Res Function(_$PhoneNumberChangedImpl) then, + ) = __$$PhoneNumberChangedImplCopyWithImpl<$Res>; + @useResult + $Res call({String phoneNumber}); +} + +/// @nodoc +class __$$PhoneNumberChangedImplCopyWithImpl<$Res> + extends _$RegisterFormEventCopyWithImpl<$Res, _$PhoneNumberChangedImpl> + implements _$$PhoneNumberChangedImplCopyWith<$Res> { + __$$PhoneNumberChangedImplCopyWithImpl( + _$PhoneNumberChangedImpl _value, + $Res Function(_$PhoneNumberChangedImpl) _then, + ) : super(_value, _then); + + /// Create a copy of RegisterFormEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? phoneNumber = null}) { + return _then( + _$PhoneNumberChangedImpl( + null == phoneNumber + ? _value.phoneNumber + : phoneNumber // ignore: cast_nullable_to_non_nullable + as String, + ), + ); + } +} + +/// @nodoc + +class _$PhoneNumberChangedImpl implements _PhoneNumberChanged { + const _$PhoneNumberChangedImpl(this.phoneNumber); + + @override + final String phoneNumber; + + @override + String toString() { + return 'RegisterFormEvent.phoneNumberChanged(phoneNumber: $phoneNumber)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$PhoneNumberChangedImpl && + (identical(other.phoneNumber, phoneNumber) || + other.phoneNumber == phoneNumber)); + } + + @override + int get hashCode => Object.hash(runtimeType, phoneNumber); + + /// Create a copy of RegisterFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$PhoneNumberChangedImplCopyWith<_$PhoneNumberChangedImpl> get copyWith => + __$$PhoneNumberChangedImplCopyWithImpl<_$PhoneNumberChangedImpl>( + this, + _$identity, + ); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String phoneNumber) phoneNumberChanged, + required TResult Function(String name) nameChanged, + required TResult Function(DateTime birthDate) birthDateChanged, + required TResult Function() submitted, + }) { + return phoneNumberChanged(phoneNumber); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String phoneNumber)? phoneNumberChanged, + TResult? Function(String name)? nameChanged, + TResult? Function(DateTime birthDate)? birthDateChanged, + TResult? Function()? submitted, + }) { + return phoneNumberChanged?.call(phoneNumber); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String phoneNumber)? phoneNumberChanged, + TResult Function(String name)? nameChanged, + TResult Function(DateTime birthDate)? birthDateChanged, + TResult Function()? submitted, + required TResult orElse(), + }) { + if (phoneNumberChanged != null) { + return phoneNumberChanged(phoneNumber); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_PhoneNumberChanged value) phoneNumberChanged, + required TResult Function(_NameChanged value) nameChanged, + required TResult Function(_BirthDateChanged value) birthDateChanged, + required TResult Function(_Submitted value) submitted, + }) { + return phoneNumberChanged(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_PhoneNumberChanged value)? phoneNumberChanged, + TResult? Function(_NameChanged value)? nameChanged, + TResult? Function(_BirthDateChanged value)? birthDateChanged, + TResult? Function(_Submitted value)? submitted, + }) { + return phoneNumberChanged?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_PhoneNumberChanged value)? phoneNumberChanged, + TResult Function(_NameChanged value)? nameChanged, + TResult Function(_BirthDateChanged value)? birthDateChanged, + TResult Function(_Submitted value)? submitted, + required TResult orElse(), + }) { + if (phoneNumberChanged != null) { + return phoneNumberChanged(this); + } + return orElse(); + } +} + +abstract class _PhoneNumberChanged implements RegisterFormEvent { + const factory _PhoneNumberChanged(final String phoneNumber) = + _$PhoneNumberChangedImpl; + + String get phoneNumber; + + /// Create a copy of RegisterFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$PhoneNumberChangedImplCopyWith<_$PhoneNumberChangedImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$NameChangedImplCopyWith<$Res> { + factory _$$NameChangedImplCopyWith( + _$NameChangedImpl value, + $Res Function(_$NameChangedImpl) then, + ) = __$$NameChangedImplCopyWithImpl<$Res>; + @useResult + $Res call({String name}); +} + +/// @nodoc +class __$$NameChangedImplCopyWithImpl<$Res> + extends _$RegisterFormEventCopyWithImpl<$Res, _$NameChangedImpl> + implements _$$NameChangedImplCopyWith<$Res> { + __$$NameChangedImplCopyWithImpl( + _$NameChangedImpl _value, + $Res Function(_$NameChangedImpl) _then, + ) : super(_value, _then); + + /// Create a copy of RegisterFormEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? name = null}) { + return _then( + _$NameChangedImpl( + null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + ), + ); + } +} + +/// @nodoc + +class _$NameChangedImpl implements _NameChanged { + const _$NameChangedImpl(this.name); + + @override + final String name; + + @override + String toString() { + return 'RegisterFormEvent.nameChanged(name: $name)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$NameChangedImpl && + (identical(other.name, name) || other.name == name)); + } + + @override + int get hashCode => Object.hash(runtimeType, name); + + /// Create a copy of RegisterFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$NameChangedImplCopyWith<_$NameChangedImpl> get copyWith => + __$$NameChangedImplCopyWithImpl<_$NameChangedImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String phoneNumber) phoneNumberChanged, + required TResult Function(String name) nameChanged, + required TResult Function(DateTime birthDate) birthDateChanged, + required TResult Function() submitted, + }) { + return nameChanged(name); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String phoneNumber)? phoneNumberChanged, + TResult? Function(String name)? nameChanged, + TResult? Function(DateTime birthDate)? birthDateChanged, + TResult? Function()? submitted, + }) { + return nameChanged?.call(name); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String phoneNumber)? phoneNumberChanged, + TResult Function(String name)? nameChanged, + TResult Function(DateTime birthDate)? birthDateChanged, + TResult Function()? submitted, + required TResult orElse(), + }) { + if (nameChanged != null) { + return nameChanged(name); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_PhoneNumberChanged value) phoneNumberChanged, + required TResult Function(_NameChanged value) nameChanged, + required TResult Function(_BirthDateChanged value) birthDateChanged, + required TResult Function(_Submitted value) submitted, + }) { + return nameChanged(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_PhoneNumberChanged value)? phoneNumberChanged, + TResult? Function(_NameChanged value)? nameChanged, + TResult? Function(_BirthDateChanged value)? birthDateChanged, + TResult? Function(_Submitted value)? submitted, + }) { + return nameChanged?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_PhoneNumberChanged value)? phoneNumberChanged, + TResult Function(_NameChanged value)? nameChanged, + TResult Function(_BirthDateChanged value)? birthDateChanged, + TResult Function(_Submitted value)? submitted, + required TResult orElse(), + }) { + if (nameChanged != null) { + return nameChanged(this); + } + return orElse(); + } +} + +abstract class _NameChanged implements RegisterFormEvent { + const factory _NameChanged(final String name) = _$NameChangedImpl; + + String get name; + + /// Create a copy of RegisterFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$NameChangedImplCopyWith<_$NameChangedImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$BirthDateChangedImplCopyWith<$Res> { + factory _$$BirthDateChangedImplCopyWith( + _$BirthDateChangedImpl value, + $Res Function(_$BirthDateChangedImpl) then, + ) = __$$BirthDateChangedImplCopyWithImpl<$Res>; + @useResult + $Res call({DateTime birthDate}); +} + +/// @nodoc +class __$$BirthDateChangedImplCopyWithImpl<$Res> + extends _$RegisterFormEventCopyWithImpl<$Res, _$BirthDateChangedImpl> + implements _$$BirthDateChangedImplCopyWith<$Res> { + __$$BirthDateChangedImplCopyWithImpl( + _$BirthDateChangedImpl _value, + $Res Function(_$BirthDateChangedImpl) _then, + ) : super(_value, _then); + + /// Create a copy of RegisterFormEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? birthDate = null}) { + return _then( + _$BirthDateChangedImpl( + null == birthDate + ? _value.birthDate + : birthDate // ignore: cast_nullable_to_non_nullable + as DateTime, + ), + ); + } +} + +/// @nodoc + +class _$BirthDateChangedImpl implements _BirthDateChanged { + const _$BirthDateChangedImpl(this.birthDate); + + @override + final DateTime birthDate; + + @override + String toString() { + return 'RegisterFormEvent.birthDateChanged(birthDate: $birthDate)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$BirthDateChangedImpl && + (identical(other.birthDate, birthDate) || + other.birthDate == birthDate)); + } + + @override + int get hashCode => Object.hash(runtimeType, birthDate); + + /// Create a copy of RegisterFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$BirthDateChangedImplCopyWith<_$BirthDateChangedImpl> get copyWith => + __$$BirthDateChangedImplCopyWithImpl<_$BirthDateChangedImpl>( + this, + _$identity, + ); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String phoneNumber) phoneNumberChanged, + required TResult Function(String name) nameChanged, + required TResult Function(DateTime birthDate) birthDateChanged, + required TResult Function() submitted, + }) { + return birthDateChanged(birthDate); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String phoneNumber)? phoneNumberChanged, + TResult? Function(String name)? nameChanged, + TResult? Function(DateTime birthDate)? birthDateChanged, + TResult? Function()? submitted, + }) { + return birthDateChanged?.call(birthDate); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String phoneNumber)? phoneNumberChanged, + TResult Function(String name)? nameChanged, + TResult Function(DateTime birthDate)? birthDateChanged, + TResult Function()? submitted, + required TResult orElse(), + }) { + if (birthDateChanged != null) { + return birthDateChanged(birthDate); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_PhoneNumberChanged value) phoneNumberChanged, + required TResult Function(_NameChanged value) nameChanged, + required TResult Function(_BirthDateChanged value) birthDateChanged, + required TResult Function(_Submitted value) submitted, + }) { + return birthDateChanged(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_PhoneNumberChanged value)? phoneNumberChanged, + TResult? Function(_NameChanged value)? nameChanged, + TResult? Function(_BirthDateChanged value)? birthDateChanged, + TResult? Function(_Submitted value)? submitted, + }) { + return birthDateChanged?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_PhoneNumberChanged value)? phoneNumberChanged, + TResult Function(_NameChanged value)? nameChanged, + TResult Function(_BirthDateChanged value)? birthDateChanged, + TResult Function(_Submitted value)? submitted, + required TResult orElse(), + }) { + if (birthDateChanged != null) { + return birthDateChanged(this); + } + return orElse(); + } +} + +abstract class _BirthDateChanged implements RegisterFormEvent { + const factory _BirthDateChanged(final DateTime birthDate) = + _$BirthDateChangedImpl; + + DateTime get birthDate; + + /// Create a copy of RegisterFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$BirthDateChangedImplCopyWith<_$BirthDateChangedImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$SubmittedImplCopyWith<$Res> { + factory _$$SubmittedImplCopyWith( + _$SubmittedImpl value, + $Res Function(_$SubmittedImpl) then, + ) = __$$SubmittedImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$SubmittedImplCopyWithImpl<$Res> + extends _$RegisterFormEventCopyWithImpl<$Res, _$SubmittedImpl> + implements _$$SubmittedImplCopyWith<$Res> { + __$$SubmittedImplCopyWithImpl( + _$SubmittedImpl _value, + $Res Function(_$SubmittedImpl) _then, + ) : super(_value, _then); + + /// Create a copy of RegisterFormEvent + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$SubmittedImpl implements _Submitted { + const _$SubmittedImpl(); + + @override + String toString() { + return 'RegisterFormEvent.submitted()'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is _$SubmittedImpl); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String phoneNumber) phoneNumberChanged, + required TResult Function(String name) nameChanged, + required TResult Function(DateTime birthDate) birthDateChanged, + required TResult Function() submitted, + }) { + return submitted(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String phoneNumber)? phoneNumberChanged, + TResult? Function(String name)? nameChanged, + TResult? Function(DateTime birthDate)? birthDateChanged, + TResult? Function()? submitted, + }) { + return submitted?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String phoneNumber)? phoneNumberChanged, + TResult Function(String name)? nameChanged, + TResult Function(DateTime birthDate)? birthDateChanged, + TResult Function()? submitted, + required TResult orElse(), + }) { + if (submitted != null) { + return submitted(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_PhoneNumberChanged value) phoneNumberChanged, + required TResult Function(_NameChanged value) nameChanged, + required TResult Function(_BirthDateChanged value) birthDateChanged, + required TResult Function(_Submitted value) submitted, + }) { + return submitted(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_PhoneNumberChanged value)? phoneNumberChanged, + TResult? Function(_NameChanged value)? nameChanged, + TResult? Function(_BirthDateChanged value)? birthDateChanged, + TResult? Function(_Submitted value)? submitted, + }) { + return submitted?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_PhoneNumberChanged value)? phoneNumberChanged, + TResult Function(_NameChanged value)? nameChanged, + TResult Function(_BirthDateChanged value)? birthDateChanged, + TResult Function(_Submitted value)? submitted, + required TResult orElse(), + }) { + if (submitted != null) { + return submitted(this); + } + return orElse(); + } +} + +abstract class _Submitted implements RegisterFormEvent { + const factory _Submitted() = _$SubmittedImpl; +} + +/// @nodoc +mixin _$RegisterFormState { + String get phoneNumber => throw _privateConstructorUsedError; + String get name => throw _privateConstructorUsedError; + DateTime get birthDate => throw _privateConstructorUsedError; + Option> get failureOrRegisterOption => + throw _privateConstructorUsedError; + bool get isSubmitting => throw _privateConstructorUsedError; + bool get showErrorMessages => throw _privateConstructorUsedError; + + /// Create a copy of RegisterFormState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $RegisterFormStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RegisterFormStateCopyWith<$Res> { + factory $RegisterFormStateCopyWith( + RegisterFormState value, + $Res Function(RegisterFormState) then, + ) = _$RegisterFormStateCopyWithImpl<$Res, RegisterFormState>; + @useResult + $Res call({ + String phoneNumber, + String name, + DateTime birthDate, + Option> failureOrRegisterOption, + bool isSubmitting, + bool showErrorMessages, + }); +} + +/// @nodoc +class _$RegisterFormStateCopyWithImpl<$Res, $Val extends RegisterFormState> + implements $RegisterFormStateCopyWith<$Res> { + _$RegisterFormStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of RegisterFormState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? phoneNumber = null, + Object? name = null, + Object? birthDate = null, + Object? failureOrRegisterOption = null, + Object? isSubmitting = null, + Object? showErrorMessages = null, + }) { + return _then( + _value.copyWith( + phoneNumber: null == phoneNumber + ? _value.phoneNumber + : phoneNumber // ignore: cast_nullable_to_non_nullable + as String, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + birthDate: null == birthDate + ? _value.birthDate + : birthDate // ignore: cast_nullable_to_non_nullable + as DateTime, + failureOrRegisterOption: null == failureOrRegisterOption + ? _value.failureOrRegisterOption + : failureOrRegisterOption // ignore: cast_nullable_to_non_nullable + as Option>, + isSubmitting: null == isSubmitting + ? _value.isSubmitting + : isSubmitting // ignore: cast_nullable_to_non_nullable + as bool, + showErrorMessages: null == showErrorMessages + ? _value.showErrorMessages + : showErrorMessages // ignore: cast_nullable_to_non_nullable + as bool, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$RegisterFormStateImplCopyWith<$Res> + implements $RegisterFormStateCopyWith<$Res> { + factory _$$RegisterFormStateImplCopyWith( + _$RegisterFormStateImpl value, + $Res Function(_$RegisterFormStateImpl) then, + ) = __$$RegisterFormStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({ + String phoneNumber, + String name, + DateTime birthDate, + Option> failureOrRegisterOption, + bool isSubmitting, + bool showErrorMessages, + }); +} + +/// @nodoc +class __$$RegisterFormStateImplCopyWithImpl<$Res> + extends _$RegisterFormStateCopyWithImpl<$Res, _$RegisterFormStateImpl> + implements _$$RegisterFormStateImplCopyWith<$Res> { + __$$RegisterFormStateImplCopyWithImpl( + _$RegisterFormStateImpl _value, + $Res Function(_$RegisterFormStateImpl) _then, + ) : super(_value, _then); + + /// Create a copy of RegisterFormState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? phoneNumber = null, + Object? name = null, + Object? birthDate = null, + Object? failureOrRegisterOption = null, + Object? isSubmitting = null, + Object? showErrorMessages = null, + }) { + return _then( + _$RegisterFormStateImpl( + phoneNumber: null == phoneNumber + ? _value.phoneNumber + : phoneNumber // ignore: cast_nullable_to_non_nullable + as String, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + birthDate: null == birthDate + ? _value.birthDate + : birthDate // ignore: cast_nullable_to_non_nullable + as DateTime, + failureOrRegisterOption: null == failureOrRegisterOption + ? _value.failureOrRegisterOption + : failureOrRegisterOption // ignore: cast_nullable_to_non_nullable + as Option>, + isSubmitting: null == isSubmitting + ? _value.isSubmitting + : isSubmitting // ignore: cast_nullable_to_non_nullable + as bool, + showErrorMessages: null == showErrorMessages + ? _value.showErrorMessages + : showErrorMessages // ignore: cast_nullable_to_non_nullable + as bool, + ), + ); + } +} + +/// @nodoc + +class _$RegisterFormStateImpl implements _RegisterFormState { + const _$RegisterFormStateImpl({ + required this.phoneNumber, + required this.name, + required this.birthDate, + required this.failureOrRegisterOption, + this.isSubmitting = false, + this.showErrorMessages = false, + }); + + @override + final String phoneNumber; + @override + final String name; + @override + final DateTime birthDate; + @override + final Option> failureOrRegisterOption; + @override + @JsonKey() + final bool isSubmitting; + @override + @JsonKey() + final bool showErrorMessages; + + @override + String toString() { + return 'RegisterFormState(phoneNumber: $phoneNumber, name: $name, birthDate: $birthDate, failureOrRegisterOption: $failureOrRegisterOption, isSubmitting: $isSubmitting, showErrorMessages: $showErrorMessages)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$RegisterFormStateImpl && + (identical(other.phoneNumber, phoneNumber) || + other.phoneNumber == phoneNumber) && + (identical(other.name, name) || other.name == name) && + (identical(other.birthDate, birthDate) || + other.birthDate == birthDate) && + (identical( + other.failureOrRegisterOption, + failureOrRegisterOption, + ) || + other.failureOrRegisterOption == failureOrRegisterOption) && + (identical(other.isSubmitting, isSubmitting) || + other.isSubmitting == isSubmitting) && + (identical(other.showErrorMessages, showErrorMessages) || + other.showErrorMessages == showErrorMessages)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + phoneNumber, + name, + birthDate, + failureOrRegisterOption, + isSubmitting, + showErrorMessages, + ); + + /// Create a copy of RegisterFormState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$RegisterFormStateImplCopyWith<_$RegisterFormStateImpl> get copyWith => + __$$RegisterFormStateImplCopyWithImpl<_$RegisterFormStateImpl>( + this, + _$identity, + ); +} + +abstract class _RegisterFormState implements RegisterFormState { + const factory _RegisterFormState({ + required final String phoneNumber, + required final String name, + required final DateTime birthDate, + required final Option> + failureOrRegisterOption, + final bool isSubmitting, + final bool showErrorMessages, + }) = _$RegisterFormStateImpl; + + @override + String get phoneNumber; + @override + String get name; + @override + DateTime get birthDate; + @override + Option> get failureOrRegisterOption; + @override + bool get isSubmitting; + @override + bool get showErrorMessages; + + /// Create a copy of RegisterFormState + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$RegisterFormStateImplCopyWith<_$RegisterFormStateImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/application/auth/register_form/register_form_event.dart b/lib/application/auth/register_form/register_form_event.dart new file mode 100644 index 0000000..b92677a --- /dev/null +++ b/lib/application/auth/register_form/register_form_event.dart @@ -0,0 +1,11 @@ +part of 'register_form_bloc.dart'; + +@freezed +class RegisterFormEvent with _$RegisterFormEvent { + const factory RegisterFormEvent.phoneNumberChanged(String phoneNumber) = + _PhoneNumberChanged; + const factory RegisterFormEvent.nameChanged(String name) = _NameChanged; + const factory RegisterFormEvent.birthDateChanged(DateTime birthDate) = + _BirthDateChanged; + const factory RegisterFormEvent.submitted() = _Submitted; +} diff --git a/lib/application/auth/register_form/register_form_state.dart b/lib/application/auth/register_form/register_form_state.dart new file mode 100644 index 0000000..4ed224b --- /dev/null +++ b/lib/application/auth/register_form/register_form_state.dart @@ -0,0 +1,20 @@ +part of 'register_form_bloc.dart'; + +@freezed +class RegisterFormState with _$RegisterFormState { + const factory RegisterFormState({ + required String phoneNumber, + required String name, + required DateTime birthDate, + required Option> failureOrRegisterOption, + @Default(false) bool isSubmitting, + @Default(false) bool showErrorMessages, + }) = _RegisterFormState; + + factory RegisterFormState.initial() => RegisterFormState( + phoneNumber: '', + failureOrRegisterOption: none(), + name: '', + birthDate: DateTime.now(), + ); +} diff --git a/lib/injection.config.dart b/lib/injection.config.dart index 3011cd6..88bfe1f 100644 --- a/lib/injection.config.dart +++ b/lib/injection.config.dart @@ -13,6 +13,8 @@ import 'package:connectivity_plus/connectivity_plus.dart' as _i895; import 'package:dio/dio.dart' as _i361; import 'package:enaklo/application/auth/check_phone_form/check_phone_form_bloc.dart' as _i869; +import 'package:enaklo/application/auth/register_form/register_form_bloc.dart' + as _i260; import 'package:enaklo/common/api/api_client.dart' as _i842; import 'package:enaklo/common/di/di_auto_route.dart' as _i619; import 'package:enaklo/common/di/di_connectivity.dart' as _i644; @@ -68,6 +70,9 @@ extension GetItInjectableX on _i174.GetIt { gh.factory<_i869.CheckPhoneFormBloc>( () => _i869.CheckPhoneFormBloc(gh<_i995.IAuthRepository>()), ); + gh.factory<_i260.RegisterFormBloc>( + () => _i260.RegisterFormBloc(gh<_i995.IAuthRepository>()), + ); return this; } }