From c0b2f2c3ed1344ed2c7fc47790255f444f59d338 Mon Sep 17 00:00:00 2001 From: cem256 Date: Mon, 27 May 2024 20:16:32 +0300 Subject: [PATCH] set min password lenght to 6, show rate app dialog after generating 5 passwords --- .../cubit/generate_password_cubit.dart | 6 ++- .../generate_password_cubit.freezed.dart | 41 +++++++++++++++---- .../cubit/generate_password_state.dart | 2 + .../view/generate_password_view.dart | 7 +++- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/lib/features/generate_password/presentation/cubit/generate_password_cubit.dart b/lib/features/generate_password/presentation/cubit/generate_password_cubit.dart index e9a1303..9753e65 100644 --- a/lib/features/generate_password/presentation/cubit/generate_password_cubit.dart +++ b/lib/features/generate_password/presentation/cubit/generate_password_cubit.dart @@ -96,7 +96,11 @@ class GeneratePasswordCubit extends Cubit { state.copyWith(passwordSettings: passwordSettings), ), (password) => emit( - state.copyWith(passwordSettings: passwordSettings, password: password), + state.copyWith( + passwordSettings: passwordSettings, + password: password, + generatedPasswordCount: state.generatedPasswordCount + 1, + ), ), ); } diff --git a/lib/features/generate_password/presentation/cubit/generate_password_cubit.freezed.dart b/lib/features/generate_password/presentation/cubit/generate_password_cubit.freezed.dart index a3746d6..78a76d0 100644 --- a/lib/features/generate_password/presentation/cubit/generate_password_cubit.freezed.dart +++ b/lib/features/generate_password/presentation/cubit/generate_password_cubit.freezed.dart @@ -19,6 +19,7 @@ mixin _$GeneratePasswordState { PasswordSettings get passwordSettings => throw _privateConstructorUsedError; String get password => throw _privateConstructorUsedError; bool get isCopied => throw _privateConstructorUsedError; + int get generatedPasswordCount => throw _privateConstructorUsedError; @JsonKey(ignore: true) $GeneratePasswordStateCopyWith get copyWith => @@ -32,7 +33,10 @@ abstract class $GeneratePasswordStateCopyWith<$Res> { _$GeneratePasswordStateCopyWithImpl<$Res, GeneratePasswordState>; @useResult $Res call( - {PasswordSettings passwordSettings, String password, bool isCopied}); + {PasswordSettings passwordSettings, + String password, + bool isCopied, + int generatedPasswordCount}); $PasswordSettingsCopyWith<$Res> get passwordSettings; } @@ -54,6 +58,7 @@ class _$GeneratePasswordStateCopyWithImpl<$Res, Object? passwordSettings = null, Object? password = null, Object? isCopied = null, + Object? generatedPasswordCount = null, }) { return _then(_value.copyWith( passwordSettings: null == passwordSettings @@ -68,6 +73,10 @@ class _$GeneratePasswordStateCopyWithImpl<$Res, ? _value.isCopied : isCopied // ignore: cast_nullable_to_non_nullable as bool, + generatedPasswordCount: null == generatedPasswordCount + ? _value.generatedPasswordCount + : generatedPasswordCount // ignore: cast_nullable_to_non_nullable + as int, ) as $Val); } @@ -90,7 +99,10 @@ abstract class _$$GeneratePasswordStateImplCopyWith<$Res> @override @useResult $Res call( - {PasswordSettings passwordSettings, String password, bool isCopied}); + {PasswordSettings passwordSettings, + String password, + bool isCopied, + int generatedPasswordCount}); @override $PasswordSettingsCopyWith<$Res> get passwordSettings; @@ -111,6 +123,7 @@ class __$$GeneratePasswordStateImplCopyWithImpl<$Res> Object? passwordSettings = null, Object? password = null, Object? isCopied = null, + Object? generatedPasswordCount = null, }) { return _then(_$GeneratePasswordStateImpl( passwordSettings: null == passwordSettings @@ -125,6 +138,10 @@ class __$$GeneratePasswordStateImplCopyWithImpl<$Res> ? _value.isCopied : isCopied // ignore: cast_nullable_to_non_nullable as bool, + generatedPasswordCount: null == generatedPasswordCount + ? _value.generatedPasswordCount + : generatedPasswordCount // ignore: cast_nullable_to_non_nullable + as int, )); } } @@ -135,7 +152,8 @@ class _$GeneratePasswordStateImpl implements _GeneratePasswordState { const _$GeneratePasswordStateImpl( {required this.passwordSettings, required this.password, - required this.isCopied}); + required this.isCopied, + required this.generatedPasswordCount}); @override final PasswordSettings passwordSettings; @@ -143,10 +161,12 @@ class _$GeneratePasswordStateImpl implements _GeneratePasswordState { final String password; @override final bool isCopied; + @override + final int generatedPasswordCount; @override String toString() { - return 'GeneratePasswordState(passwordSettings: $passwordSettings, password: $password, isCopied: $isCopied)'; + return 'GeneratePasswordState(passwordSettings: $passwordSettings, password: $password, isCopied: $isCopied, generatedPasswordCount: $generatedPasswordCount)'; } @override @@ -159,12 +179,14 @@ class _$GeneratePasswordStateImpl implements _GeneratePasswordState { (identical(other.password, password) || other.password == password) && (identical(other.isCopied, isCopied) || - other.isCopied == isCopied)); + other.isCopied == isCopied) && + (identical(other.generatedPasswordCount, generatedPasswordCount) || + other.generatedPasswordCount == generatedPasswordCount)); } @override - int get hashCode => - Object.hash(runtimeType, passwordSettings, password, isCopied); + int get hashCode => Object.hash(runtimeType, passwordSettings, password, + isCopied, generatedPasswordCount); @JsonKey(ignore: true) @override @@ -178,7 +200,8 @@ abstract class _GeneratePasswordState implements GeneratePasswordState { const factory _GeneratePasswordState( {required final PasswordSettings passwordSettings, required final String password, - required final bool isCopied}) = _$GeneratePasswordStateImpl; + required final bool isCopied, + required final int generatedPasswordCount}) = _$GeneratePasswordStateImpl; @override PasswordSettings get passwordSettings; @@ -187,6 +210,8 @@ abstract class _GeneratePasswordState implements GeneratePasswordState { @override bool get isCopied; @override + int get generatedPasswordCount; + @override @JsonKey(ignore: true) _$$GeneratePasswordStateImplCopyWith<_$GeneratePasswordStateImpl> get copyWith => throw _privateConstructorUsedError; diff --git a/lib/features/generate_password/presentation/cubit/generate_password_state.dart b/lib/features/generate_password/presentation/cubit/generate_password_state.dart index a74575f..65c61b5 100644 --- a/lib/features/generate_password/presentation/cubit/generate_password_state.dart +++ b/lib/features/generate_password/presentation/cubit/generate_password_state.dart @@ -6,11 +6,13 @@ class GeneratePasswordState with _$GeneratePasswordState { required PasswordSettings passwordSettings, required String password, required bool isCopied, + required int generatedPasswordCount, }) = _GeneratePasswordState; factory GeneratePasswordState.initial() => GeneratePasswordState( passwordSettings: PasswordSettings.initial(), password: '', isCopied: false, + generatedPasswordCount: 0, ); } diff --git a/lib/features/generate_password/presentation/view/generate_password_view.dart b/lib/features/generate_password/presentation/view/generate_password_view.dart index 0ff1240..48d433b 100644 --- a/lib/features/generate_password/presentation/view/generate_password_view.dart +++ b/lib/features/generate_password/presentation/view/generate_password_view.dart @@ -8,6 +8,7 @@ import 'package:password_generator/app/theme/constants/theme_constants.dart'; import 'package:password_generator/app/widgets/container/custom_container.dart'; import 'package:password_generator/app/widgets/drawer/custom_drawer.dart'; import 'package:password_generator/core/extensions/context_extensions.dart'; +import 'package:password_generator/core/utils/rate_app/rate_app_utils.dart'; import 'package:password_generator/core/utils/snackbar/snackbar_utils.dart'; import 'package:password_generator/features/generate_password/presentation/cubit/generate_password_cubit.dart'; import 'package:password_generator/features/password_history/cubit/password_history_cubit.dart'; @@ -21,7 +22,7 @@ class GeneratePasswordView extends StatelessWidget { @override Widget build(BuildContext context) { return BlocListener( - listener: (context, state) { + listener: (context, state) async { if (state.isCopied) { SnackbarUtils.showSnackbar( context: context, @@ -29,6 +30,10 @@ class GeneratePasswordView extends StatelessWidget { ); context.read().addToHistory(password: state.password); } + // Show rate app dialog after generating 5 passwords + if (state.generatedPasswordCount == 5) { + await RateAppUtils.rateApp(); + } }, child: Scaffold( appBar: AppBar(