diff --git a/lib/presentation/auth/auth_screen.dart b/lib/presentation/auth/auth_screen.dart index 06ac2cb..964fb52 100644 --- a/lib/presentation/auth/auth_screen.dart +++ b/lib/presentation/auth/auth_screen.dart @@ -27,16 +27,16 @@ class _AuthScreenState extends State context: context, builder: (context) => AlertDialog( shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.0), + borderRadius: BorderRadius.circular(10.sp), // Responsive radius ), - contentPadding: EdgeInsets.all(25.0), + contentPadding: EdgeInsets.all(25.sp), // Responsive padding title: Text( 'Confirm Exit', - style: TextStyle(fontSize: 25, color: kYellow), + style: TextStyle(fontSize: 25.sp, color: kYellow), // Responsive font ), content: Text( 'Do you really want to exit?', - style: TextStyle(fontSize: 18, color: kBlack), + style: TextStyle(fontSize: 18.sp, color: kBlack), // Responsive font ), actions: [ HikeButton( @@ -58,16 +58,10 @@ class _AuthScreenState extends State PageController _pageController = PageController(); - Color leftColor = Colors.white; - Color rightColor = Colors.black; - int _currentPage = 0; @override Widget build(BuildContext context) { - print( - "_currentPage: $_currentPage", - ); Size screensize = MediaQuery.of(context).size; return PopScope( @@ -94,12 +88,12 @@ class _AuthScreenState extends State context.read().navigate(); } else if (state is AuthErrorState) { utils.showSnackBar(state.error!, context, - duration: Duration(seconds: 2)); + duration: const Duration(seconds: 2)); } }, builder: (context, state) { return state is AuthLoadingState - ? LoadingScreen() + ? const LoadingScreen() : Scaffold( resizeToAvoidBottomInset: true, body: SafeArea( @@ -205,21 +199,20 @@ class _AuthScreenState extends State loginPasswordController.text.trim(), ); } else { - utils.showSnackBar( - 'Please complete all the fields', context); + utils.showSnackBar('Please complete all the fields', context); } }, style: ElevatedButton.styleFrom( backgroundColor: Colors.teal, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(14), + borderRadius: BorderRadius.circular(14.sp), // Responsive radius ), minimumSize: Size(screensize.width - 70, 45)), - child: const Text( + child: Text( 'Continue with Email', style: TextStyle( color: Colors.black, - fontSize: 16, + fontSize: 16.sp, // Responsive font ), ), ); @@ -280,7 +273,7 @@ class _AuthScreenState extends State height: 1.2.h, ), Container( - decoration: BoxDecoration( + decoration: const BoxDecoration( // Add const borderRadius: BorderRadius.all(Radius.circular(5.0)), ), child: BlocBuilder( @@ -293,21 +286,20 @@ class _AuthScreenState extends State signUpEmailController.text.trim(), signUpPasswordController.text.trim()); } else { - utils.showSnackBar( - 'Please complete all the fields', context); + utils.showSnackBar('Please complete all the fields', context); } }, style: ElevatedButton.styleFrom( backgroundColor: Colors.teal, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(14), + borderRadius: BorderRadius.circular(14.sp), // Responsive radius ), minimumSize: Size(screensize.width - 70, 45)), - child: const Text( + child: Text( 'Continue with Email', style: TextStyle( color: Colors.black, - fontSize: 16, + fontSize: 16.sp, // Responsive font ), ), ); @@ -332,7 +324,7 @@ class _AuthScreenState extends State : 'Already have an account?', style: TextStyle( color: Colors.grey, - fontSize: 14, + fontSize: 14.sp, // Responsive font ), ), TextButton( @@ -350,9 +342,9 @@ class _AuthScreenState extends State child: Text( _currentPage == 0 ? 'Sign up' : 'Sign in', style: TextStyle( - color: Color(0xFF6A1B9A), + color: const Color(0xFF6A1B9A), fontWeight: FontWeight.bold, - fontSize: 14, + fontSize: 14.sp, // Responsive font ), ), ), @@ -362,24 +354,24 @@ class _AuthScreenState extends State SizedBox( width: 200, child: Row( - children: const [ - Expanded( + children: [ + const Expanded( // Add const child: Divider( color: Colors.grey, thickness: 1, ), ), Padding( - padding: EdgeInsets.symmetric(horizontal: 8.0), + padding: EdgeInsets.symmetric(horizontal: 8.sp), // Responsive padding child: Text( 'or', style: TextStyle( color: Colors.grey, - fontSize: 14, + fontSize: 14.sp, // Responsive font ), ), ), - Expanded( + const Expanded( // Add const child: Divider( color: Colors.grey, thickness: 1, @@ -410,4 +402,4 @@ class _AuthScreenState extends State ], ); } -} +} \ No newline at end of file diff --git a/lib/presentation/auth/verification_cubit/verification_cubit.dart b/lib/presentation/auth/verification_cubit/verification_cubit.dart index 08d1b97..bc55cef 100644 --- a/lib/presentation/auth/verification_cubit/verification_cubit.dart +++ b/lib/presentation/auth/verification_cubit/verification_cubit.dart @@ -5,27 +5,29 @@ import 'package:beacon/presentation/auth/verification_cubit/verification_state.d import 'package:flutter_bloc/flutter_bloc.dart'; class VerificationCubit extends Cubit { - AuthUseCase _authUseCase; + final AuthUseCase _authUseCase; + VerificationCubit(this._authUseCase) : super(InitialOTPState()); - emitVerificationSentstate(String otp) { + void emitVerificationSentState(String otp) { emit(OTPSentState(otp: otp)); } - _clear() async { + Future _clearStoredOTPData() async { await sp.deleteData('time'); await sp.deleteData('otp'); } Future sendEmailVerification() async { emit(OTPSendingState()); + final dataState = await _authUseCase.sendVerificationCode(); - if (dataState is DataSuccess && dataState.data != null) { + if (dataState is DataSuccess && dataState.data != null) { await sp.init(); await sp.saveData('time', DateTime.now().toIso8601String()); await sp.saveData('otp', dataState.data!); - emit(OTPSentState(otp: dataState.data)); + emit(OTPSentState(otp: dataState.data!)); } else { emit(OTPFailureState()); } @@ -36,10 +38,10 @@ class VerificationCubit extends Cubit { final dataState = await _authUseCase.completeVerification(); - if (dataState is DataSuccess && dataState.data != null) { - _clear(); + if (dataState is DataSuccess && dataState.data == true) { + await _clearStoredOTPData(); appRouter.replaceNamed('/home'); - } else if (dataState is DataFailed) { + } else { emit(OTPFailureState()); } } diff --git a/lib/presentation/auth/verification_cubit/verification_state.dart b/lib/presentation/auth/verification_cubit/verification_state.dart index 18c1ef9..f986b75 100644 --- a/lib/presentation/auth/verification_cubit/verification_state.dart +++ b/lib/presentation/auth/verification_cubit/verification_state.dart @@ -4,10 +4,10 @@ part 'verification_state.freezed.dart'; @freezed class OTPVerificationState with _$OTPVerificationState { - factory OTPVerificationState.initial() = InitialOTPState; - factory OTPVerificationState.otpSending() = OTPSendingState; - factory OTPVerificationState.otpSent({String? otp}) = OTPSentState; - factory OTPVerificationState.otpVerifying() = OTPVerifyingState; - factory OTPVerificationState.otpVerified() = OTPVerifiedState; - factory OTPVerificationState.failure() = OTPFailureState; + const factory OTPVerificationState.initial() = InitialOTPState; + const factory OTPVerificationState.otpSending() = OTPSendingState; + const factory OTPVerificationState.otpSent({String? otp}) = OTPSentState; + const factory OTPVerificationState.otpVerifying() = OTPVerifyingState; + const factory OTPVerificationState.otpVerified() = OTPVerifiedState; + const factory OTPVerificationState.failure({String? errorMessage}) = OTPFailureState; } diff --git a/lib/presentation/auth/verification_cubit/verification_state.freezed.dart b/lib/presentation/auth/verification_cubit/verification_state.freezed.dart index 688d823..1667fdb 100644 --- a/lib/presentation/auth/verification_cubit/verification_state.freezed.dart +++ b/lib/presentation/auth/verification_cubit/verification_state.freezed.dart @@ -96,21 +96,19 @@ class _$OTPVerificationStateCopyWithImpl<$Res, // ignore: unused_field final $Val _value; // ignore: unused_field - final $Res Function($Val) _then; -} - + final $Res Function(Val\) \_then; +\} /// @nodoc -abstract class _$$InitialOTPStateImplCopyWith<$Res> { - factory _$$InitialOTPStateImplCopyWith(_$InitialOTPStateImpl value, +abstract class \_$InitialOTPStateImplCopyWith<Res\> \{ +factory \_$InitialOTPStateImplCopyWith(_$InitialOTPStateImpl value, $Res Function(_$InitialOTPStateImpl) then) = - __$$InitialOTPStateImplCopyWithImpl<$Res>; -} - + __$$InitialOTPStateImplCopyWithImpl<Res\>; +\} /// @nodoc -class __$$InitialOTPStateImplCopyWithImpl<$Res> +class \_\_$InitialOTPStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$InitialOTPStateImpl> - implements _$$InitialOTPStateImplCopyWith<$Res> { - __$$InitialOTPStateImplCopyWithImpl( + implements _$$InitialOTPStateImplCopyWith<Res\> \{ +\_\_$InitialOTPStateImplCopyWithImpl( _$InitialOTPStateImpl _value, $Res Function(_$InitialOTPStateImpl) _then) : super(_value, _then); } @@ -118,7 +116,7 @@ class __$$InitialOTPStateImplCopyWithImpl<$Res> /// @nodoc class _$InitialOTPStateImpl implements InitialOTPState { - _$InitialOTPStateImpl(); + const _$InitialOTPStateImpl(); @override String toString() { @@ -222,21 +220,20 @@ class _$InitialOTPStateImpl implements InitialOTPState { } abstract class InitialOTPState implements OTPVerificationState { - factory InitialOTPState() = _$InitialOTPStateImpl; + const factory InitialOTPState() = _$InitialOTPStateImpl; } /// @nodoc -abstract class _$$OTPSendingStateImplCopyWith<$Res> { - factory _$$OTPSendingStateImplCopyWith(_$OTPSendingStateImpl value, +abstract class _$$OTPSendingStateImplCopyWith<Res\> \{ +factory \_$OTPSendingStateImplCopyWith(_$OTPSendingStateImpl value, $Res Function(_$OTPSendingStateImpl) then) = - __$$OTPSendingStateImplCopyWithImpl<$Res>; -} - + __$$OTPSendingStateImplCopyWithImpl<Res\>; +\} /// @nodoc -class __$$OTPSendingStateImplCopyWithImpl<$Res> +class \_\_$OTPSendingStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$OTPSendingStateImpl> - implements _$$OTPSendingStateImplCopyWith<$Res> { - __$$OTPSendingStateImplCopyWithImpl( + implements _$$OTPSendingStateImplCopyWith<Res\> \{ +\_\_$OTPSendingStateImplCopyWithImpl( _$OTPSendingStateImpl _value, $Res Function(_$OTPSendingStateImpl) _then) : super(_value, _then); } @@ -244,7 +241,7 @@ class __$$OTPSendingStateImplCopyWithImpl<$Res> /// @nodoc class _$OTPSendingStateImpl implements OTPSendingState { - _$OTPSendingStateImpl(); + const _$OTPSendingStateImpl(); @override String toString() { @@ -348,23 +345,22 @@ class _$OTPSendingStateImpl implements OTPSendingState { } abstract class OTPSendingState implements OTPVerificationState { - factory OTPSendingState() = _$OTPSendingStateImpl; + const factory OTPSendingState() = _$OTPSendingStateImpl; } /// @nodoc -abstract class _$$OTPSentStateImplCopyWith<$Res> { - factory _$$OTPSentStateImplCopyWith( +abstract class _$$OTPSentStateImplCopyWith<Res\> \{ +factory \_$OTPSentStateImplCopyWith( _$OTPSentStateImpl value, $Res Function(_$OTPSentStateImpl) then) = __$$OTPSentStateImplCopyWithImpl<$Res>; @useResult - $Res call({String? otp}); -} - + Res call\(\{String? otp\}\); +\} /// @nodoc -class __$$OTPSentStateImplCopyWithImpl<$Res> +class \_\_$OTPSentStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$OTPSentStateImpl> - implements _$$OTPSentStateImplCopyWith<$Res> { - __$$OTPSentStateImplCopyWithImpl( + implements _$$OTPSentStateImplCopyWith<Res\> \{ +\_\_$OTPSentStateImplCopyWithImpl( _$OTPSentStateImpl _value, $Res Function(_$OTPSentStateImpl) _then) : super(_value, _then); @@ -385,7 +381,7 @@ class __$$OTPSentStateImplCopyWithImpl<$Res> /// @nodoc class _$OTPSentStateImpl implements OTPSentState { - _$OTPSentStateImpl({this.otp}); + const _$OTPSentStateImpl({this.otp}); @override final String? otp; @@ -500,7 +496,7 @@ class _$OTPSentStateImpl implements OTPSentState { } abstract class OTPSentState implements OTPVerificationState { - factory OTPSentState({final String? otp}) = _$OTPSentStateImpl; + const factory OTPSentState({final String? otp}) = _$OTPSentStateImpl; String? get otp; @JsonKey(ignore: true) @@ -509,17 +505,16 @@ abstract class OTPSentState implements OTPVerificationState { } /// @nodoc -abstract class _$$OTPVerifyingStateImplCopyWith<$Res> { - factory _$$OTPVerifyingStateImplCopyWith(_$OTPVerifyingStateImpl value, +abstract class _$$OTPVerifyingStateImplCopyWith<Res\> \{ +factory \_$OTPVerifyingStateImplCopyWith(_$OTPVerifyingStateImpl value, $Res Function(_$OTPVerifyingStateImpl) then) = - __$$OTPVerifyingStateImplCopyWithImpl<$Res>; -} - + __$$OTPVerifyingStateImplCopyWithImpl<Res\>; +\} /// @nodoc -class __$$OTPVerifyingStateImplCopyWithImpl<$Res> +class \_\_$OTPVerifyingStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$OTPVerifyingStateImpl> - implements _$$OTPVerifyingStateImplCopyWith<$Res> { - __$$OTPVerifyingStateImplCopyWithImpl(_$OTPVerifyingStateImpl _value, + implements _$$OTPVerifyingStateImplCopyWith<Res\> \{ +\_\_$OTPVerifyingStateImplCopyWithImpl(_$OTPVerifyingStateImpl _value, $Res Function(_$OTPVerifyingStateImpl) _then) : super(_value, _then); } @@ -527,7 +522,7 @@ class __$$OTPVerifyingStateImplCopyWithImpl<$Res> /// @nodoc class _$OTPVerifyingStateImpl implements OTPVerifyingState { - _$OTPVerifyingStateImpl(); + const _$OTPVerifyingStateImpl(); @override String toString() { @@ -631,21 +626,20 @@ class _$OTPVerifyingStateImpl implements OTPVerifyingState { } abstract class OTPVerifyingState implements OTPVerificationState { - factory OTPVerifyingState() = _$OTPVerifyingStateImpl; + const factory OTPVerifyingState() = _$OTPVerifyingStateImpl; } /// @nodoc -abstract class _$$OTPVerifiedStateImplCopyWith<$Res> { - factory _$$OTPVerifiedStateImplCopyWith(_$OTPVerifiedStateImpl value, +abstract class _$$OTPVerifiedStateImplCopyWith<Res\> \{ +factory \_$OTPVerifiedStateImplCopyWith(_$OTPVerifiedStateImpl value, $Res Function(_$OTPVerifiedStateImpl) then) = - __$$OTPVerifiedStateImplCopyWithImpl<$Res>; -} - + __$$OTPVerifiedStateImplCopyWithImpl<Res\>; +\} /// @nodoc -class __$$OTPVerifiedStateImplCopyWithImpl<$Res> +class \_\_$OTPVerifiedStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$OTPVerifiedStateImpl> - implements _$$OTPVerifiedStateImplCopyWith<$Res> { - __$$OTPVerifiedStateImplCopyWithImpl(_$OTPVerifiedStateImpl _value, + implements _$$OTPVerifiedStateImplCopyWith<Res\> \{ +\_\_$OTPVerifiedStateImplCopyWithImpl(_$OTPVerifiedStateImpl _value, $Res Function(_$OTPVerifiedStateImpl) _then) : super(_value, _then); } @@ -653,7 +647,7 @@ class __$$OTPVerifiedStateImplCopyWithImpl<$Res> /// @nodoc class _$OTPVerifiedStateImpl implements OTPVerifiedState { - _$OTPVerifiedStateImpl(); + const _$OTPVerifiedStateImpl(); @override String toString() { @@ -757,7 +751,7 @@ class _$OTPVerifiedStateImpl implements OTPVerifiedState { } abstract class OTPVerifiedState implements OTPVerificationState { - factory OTPVerifiedState() = _$OTPVerifiedStateImpl; + const factory OTPVerifiedState() = _$OTPVerifiedStateImpl; } /// @nodoc @@ -771,15 +765,15 @@ abstract class _$$OTPFailureStateImplCopyWith<$Res> { class __$$OTPFailureStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$OTPFailureStateImpl> implements _$$OTPFailureStateImplCopyWith<$Res> { - __$$OTPFailureStateImplCopyWithImpl( - _$OTPFailureStateImpl _value, $Res Function(_$OTPFailureStateImpl) _then) + __$$OTPFailureStateImplCopyWithImpl(_$OTPFailureStateImpl _value, + $Res Function(_$OTPFailureStateImpl) _then) : super(_value, _then); } /// @nodoc class _$OTPFailureStateImpl implements OTPFailureState { - _$OTPFailureStateImpl(); + const _$OTPFailureStateImpl(); @override String toString() { @@ -883,5 +877,5 @@ class _$OTPFailureStateImpl implements OTPFailureState { } abstract class OTPFailureState implements OTPVerificationState { - factory OTPFailureState() = _$OTPFailureStateImpl; -} + const factory OTPFailureState() = _$OTPFailureStateImpl; +} \ No newline at end of file