mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-08 23:18:16 -07:00
Init repo
This commit is contained in:
commit
764b6034e3
566 changed files with 212335 additions and 0 deletions
72
lib/screens/shared/authenticate_button_options.dart
Normal file
72
lib/screens/shared/authenticate_button_options.dart
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import 'package:ficonsax/ficonsax.dart';
|
||||
import 'package:fladder/models/account_model.dart';
|
||||
import 'package:fladder/screens/shared/fladder_snackbar.dart';
|
||||
import 'package:fladder/screens/shared/passcode_input.dart';
|
||||
import 'package:fladder/util/auth_service.dart';
|
||||
import 'package:fladder/util/list_padding.dart';
|
||||
import 'package:fladder/util/localization_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
showAuthOptionsDialogue(
|
||||
BuildContext context,
|
||||
AccountModel currentUser,
|
||||
Function(AccountModel) setMethod,
|
||||
) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog.adaptive(
|
||||
scrollable: true,
|
||||
icon: const Icon(IconsaxBold.lock_1),
|
||||
title: Text(context.localized.appLockTitle(currentUser.name)),
|
||||
actionsOverflowDirection: VerticalDirection.down,
|
||||
actions: Authentication.values
|
||||
.where((element) => element.available(context))
|
||||
.map(
|
||||
(method) => SizedBox(
|
||||
height: 50,
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () async {
|
||||
switch (method) {
|
||||
case Authentication.autoLogin:
|
||||
setMethod.call(currentUser.copyWith(authMethod: method));
|
||||
break;
|
||||
case Authentication.biometrics:
|
||||
final authenticated = await AuthService.authenticateUser(context, currentUser);
|
||||
if (authenticated) {
|
||||
setMethod.call(currentUser.copyWith(authMethod: method));
|
||||
} else if (context.mounted) {
|
||||
fladderSnackbar(context, title: context.localized.biometricsFailedCheckAgain);
|
||||
}
|
||||
break;
|
||||
case Authentication.passcode:
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
Future.microtask(() {
|
||||
showPassCodeDialog(context, (newPin) {
|
||||
setMethod.call(currentUser.copyWith(authMethod: method, localPin: newPin));
|
||||
});
|
||||
});
|
||||
}
|
||||
return;
|
||||
case Authentication.none:
|
||||
setMethod.call(currentUser.copyWith(authMethod: method));
|
||||
break;
|
||||
}
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
icon: Icon(method.icon),
|
||||
label: Text(
|
||||
method.name(context),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList()
|
||||
.addPadding(const EdgeInsets.symmetric(vertical: 8)),
|
||||
),
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue