Skip to content

Commit

Permalink
set min password lenght to 6, show rate app dialog after generating 5…
Browse files Browse the repository at this point in the history
… passwords
  • Loading branch information
cem256 committed May 27, 2024
1 parent 9fe10c0 commit c0b2f2c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ class GeneratePasswordCubit extends Cubit<GeneratePasswordState> {
state.copyWith(passwordSettings: passwordSettings),
),
(password) => emit(
state.copyWith(passwordSettings: passwordSettings, password: password),
state.copyWith(
passwordSettings: passwordSettings,
password: password,
generatedPasswordCount: state.generatedPasswordCount + 1,
),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GeneratePasswordState> get copyWith =>
Expand All @@ -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;
}
Expand All @@ -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
Expand All @@ -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);
}

Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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,
));
}
}
Expand All @@ -135,18 +152,21 @@ 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;
@override
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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -21,14 +22,18 @@ class GeneratePasswordView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocListener<GeneratePasswordCubit, GeneratePasswordState>(
listener: (context, state) {
listener: (context, state) async {
if (state.isCopied) {
SnackbarUtils.showSnackbar(
context: context,
message: context.l10n.password_copied,
);
context.read<PasswordHistoryCubit>().addToHistory(password: state.password);
}
// Show rate app dialog after generating 5 passwords
if (state.generatedPasswordCount == 5) {
await RateAppUtils.rateApp();
}
},
child: Scaffold(
appBar: AppBar(
Expand Down

0 comments on commit c0b2f2c

Please sign in to comment.