Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow applock without account #253

Merged
merged 3 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
.vscode/

# Flutter/Dart/Pub related
**/doc/api/
Expand Down Expand Up @@ -58,4 +58,4 @@ windows/flutter/generated_plugin_registrant.cc
macos/Flutter/GeneratedPluginRegistrant.swift

# FVM Version Cache
.fvm/
.fvm/
4 changes: 3 additions & 1 deletion lib/core/widgets/submit_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ class SubmitButton extends StatelessWidget {
final bool isLoading;
final Function() onSubmitted;
final String buttonText;
final bool isDisabled;
const SubmitButton({
Key? key,
required this.isLoading,
required this.onSubmitted,
required this.buttonText,
this.isDisabled = false,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return ElevatedButton.icon(
icon: const SizedBox.shrink(),
onPressed: isLoading ? null : onSubmitted,
onPressed: isLoading || isDisabled ? null : onSubmitted,
label: Text(
buttonText,
style: const TextStyle(
Expand Down
75 changes: 75 additions & 0 deletions lib/features/auth/presentation/widgets/applock_warning_popup.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:dairy_app/app/themes/theme_extensions/popup_theme_extensions.dart';
import 'package:dairy_app/core/widgets/cancel_button.dart';
import 'package:dairy_app/core/widgets/glass_dialog.dart';
import 'package:dairy_app/core/widgets/submit_button.dart';
import 'package:dairy_app/generated/l10n.dart';
import 'package:flutter/material.dart';

Future<dynamic> applockWarningPopup({
required BuildContext context,
required String warningMessage,
}) {
final mainTextColor =
Theme.of(context).extension<PopupThemeExtensions>()!.mainTextColor;

var checkboxAccepted = false;

return showCustomDialog(
context: context,
child: Container(
width: 300,
padding: const EdgeInsets.all(20.0),
child: StatefulBuilder(builder: (context, setState) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
S.current.warning,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: mainTextColor,
),
),
const SizedBox(height: 20),
Text(
warningMessage,
style: TextStyle(
color: mainTextColor,
),
),
const SizedBox(height: 10),
CheckboxListTile(
contentPadding: EdgeInsets.zero,
title: Text(S.current.acceptRisk),
value: checkboxAccepted,
controlAffinity: ListTileControlAffinity.leading,
onChanged: (bool? value) {
setState(() {
checkboxAccepted = value!;
});
},
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CancelButton(
buttonText: S.current.cancel,
onPressed: () => Navigator.of(context).pop(false),
),
const SizedBox(width: 20),
SubmitButton(
isLoading: false,
onSubmitted: () => Navigator.of(context).pop(true),
buttonText: S.current.done,
isDisabled: !checkboxAccepted,
),
],
)
],
);
}),
),
);
}
17 changes: 13 additions & 4 deletions lib/features/auth/presentation/widgets/security_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:dairy_app/features/auth/core/constants.dart';
import 'package:dairy_app/features/auth/domain/repositories/authentication_repository.dart';
import 'package:dairy_app/features/auth/presentation/bloc/auth_session/auth_session_bloc.dart';
import 'package:dairy_app/features/auth/presentation/bloc/user_config/user_config_cubit.dart';
import 'package:dairy_app/features/auth/presentation/widgets/applock_warning_popup.dart';
import 'package:dairy_app/features/auth/presentation/widgets/email_change_popup.dart';
import 'package:dairy_app/features/auth/presentation/widgets/password_enter_popup.dart';
import 'package:dairy_app/features/auth/presentation/widgets/password_reset_popup.dart';
Expand Down Expand Up @@ -70,8 +71,12 @@ class SecuritySettings extends StatelessWidget {
}

if (userId == GuestUserDetails.guestUserId) {
showToast(S.current.pleaseSetupYourAccountToUseThisFeature);
return;
final checkboxAccepted = await applockWarningPopup(
context: context,
warningMessage: S.current.fingerprintWarningMessage,
);

if (!checkboxAccepted) return;
}

try {
Expand Down Expand Up @@ -106,8 +111,12 @@ class SecuritySettings extends StatelessWidget {
}

if (userId == GuestUserDetails.guestUserId) {
showToast(S.current.pleaseSetupYourAccountToUseThisFeature);
return;
final checkboxAccepted = await applockWarningPopup(
context: context,
warningMessage: S.current.pinWarningMessage,
);

if (!checkboxAccepted) return;
}

if (value == true) {
Expand Down
4 changes: 0 additions & 4 deletions lib/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import 'messages_ru.dart' as messages_ru;
import 'messages_sk.dart' as messages_sk;
import 'messages_sw.dart' as messages_sw;
import 'messages_te.dart' as messages_te;
import 'messages_tr.dart' as messages_tr;
import 'messages_zh.dart' as messages_zh;

typedef Future<dynamic> LibraryLoader();
Expand All @@ -59,7 +58,6 @@ Map<String, LibraryLoader> _deferredLibraries = {
'sk': () => new SynchronousFuture(null),
'sw': () => new SynchronousFuture(null),
'te': () => new SynchronousFuture(null),
'tr': () => new SynchronousFuture(null),
'zh': () => new SynchronousFuture(null),
};

Expand Down Expand Up @@ -103,8 +101,6 @@ MessageLookupByLibrary? _findExact(String localeName) {
return messages_sw.messages;
case 'te':
return messages_te.messages;
case 'tr':
return messages_tr.messages;
case 'zh':
return messages_zh.messages;
default:
Expand Down
7 changes: 7 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class MessageLookup extends MessageLookupByLibrary {

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"acceptRisk": MessageLookupByLibrary.simpleMessage(
"I accept the risk to continue"),
"accountSetupSuccessful":
MessageLookupByLibrary.simpleMessage("Account setup successful"),
"alreadyHaveAnAccount":
Expand Down Expand Up @@ -101,6 +103,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Fingerprint auth should be enabled in device settings"),
"fingerprintLoginFailed":
MessageLookupByLibrary.simpleMessage("Fingerprint login failed"),
"fingerprintWarningMessage": MessageLookupByLibrary.simpleMessage(
"You are about to enable fingerprint without creating account, if there is any hardware damage to fingerprint sensor you will be locked out of the app. If this is not intentional, please setup your account from first option in settings menu, if this is intentional, please make sure to enable cloud backup for your notes"),
"fontFamily": MessageLookupByLibrary.simpleMessage("Font Family"),
"forgotPassword":
MessageLookupByLibrary.simpleMessage("Forgot password"),
Expand Down Expand Up @@ -159,6 +163,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Please enter a 4-digit PIN"),
"pinResetSuccessful":
MessageLookupByLibrary.simpleMessage("PIN confirmation feeling"),
"pinWarningMessage": MessageLookupByLibrary.simpleMessage(
"You are about to enable PIN lock without creating account, if you forget your PIN you will be locked out of the app. If this is not intentional, please setup your account from first option in settings menu, if this is intentional, please make sure to enable cloud backup for your notes"),
"pinsDontMatch":
MessageLookupByLibrary.simpleMessage("PINs don\'t match"),
"pleaseSetupYourAccountToUseThisFeature":
Expand Down Expand Up @@ -205,6 +211,7 @@ class MessageLookup extends MessageLookupByLibrary {
"unexpectedErrorOccured":
MessageLookupByLibrary.simpleMessage("Unexpected error occured"),
"video": MessageLookupByLibrary.simpleMessage("Video"),
"warning": MessageLookupByLibrary.simpleMessage("Warning"),
"webdavURL": MessageLookupByLibrary.simpleMessage("WebDAV URL"),
"wrongPIN": MessageLookupByLibrary.simpleMessage("Wrong PIN"),
"youHaveUnsavedChanges":
Expand Down
Loading