yubioath-flutter/lib/fido/views/key_actions.dart

101 lines
3.6 KiB
Dart
Raw Normal View History

/*
* Copyright (C) 2023 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import '../../app/message.dart';
import '../../app/models.dart';
2023-06-09 15:46:16 +03:00
import '../../app/views/action_list.dart';
2023-10-06 11:49:01 +03:00
import '../features.dart' as features;
import '../keys.dart' as keys;
import '../models.dart';
import 'add_fingerprint_dialog.dart';
import 'pin_dialog.dart';
bool fidoShowActionsNotifier(FidoState state) {
2023-09-27 16:12:31 +03:00
return (state.alwaysUv && !state.hasPin) ||
state.bioEnroll == false ||
state.forcePinChange;
}
Widget fidoBuildActions(
BuildContext context, DeviceNode node, FidoState state, int fingerprints) {
2023-02-28 21:05:46 +03:00
final l10n = AppLocalizations.of(context)!;
2023-09-27 16:12:31 +03:00
final colors = Theme.of(context).buttonTheme.colorScheme ??
Theme.of(context).colorScheme;
2024-01-09 14:50:26 +03:00
return Column(
children: [
if (state.bioEnroll != null)
ActionListSection(
l10n.s_setup,
children: [
ActionListItem(
key: keys.addFingerprintAction,
feature: features.actionsAddFingerprint,
actionStyle: ActionStyle.primary,
icon: const Icon(Icons.fingerprint_outlined),
title: l10n.s_add_fingerprint,
subtitle: state.unlocked
? l10n.l_fingerprints_used(fingerprints)
: state.hasPin
? l10n.l_unlock_pin_first
: l10n.l_set_pin_first,
trailing: fingerprints == 0
? Icon(Icons.warning_amber, color: colors.tertiary)
: null,
onTap: state.unlocked && fingerprints < 5
? (context) {
Navigator.of(context).popUntil((route) => route.isFirst);
showBlurDialog(
context: context,
builder: (context) => AddFingerprintDialog(node.path),
);
}
: null,
2023-12-20 17:09:31 +03:00
),
2024-01-09 14:50:26 +03:00
],
),
ActionListSection(
l10n.s_manage,
children: [
ActionListItem(
key: keys.managePinAction,
feature: features.actionsPin,
icon: const Icon(Icons.pin_outlined),
title: state.hasPin ? l10n.s_change_pin : l10n.s_set_pin,
subtitle: state.hasPin
? (state.forcePinChange
? l10n.s_pin_change_required
: l10n.s_fido_pin_protection)
: l10n.l_fido_pin_protection_optional,
trailing: state.alwaysUv && !state.hasPin || state.forcePinChange
? Icon(Icons.warning_amber, color: colors.tertiary)
: null,
onTap: (context) {
Navigator.of(context).popUntil((route) => route.isFirst);
showBlurDialog(
context: context,
builder: (context) => FidoPinDialog(node.path, state),
);
}),
2023-12-20 17:09:31 +03:00
],
2024-01-09 14:50:26 +03:00
)
],
);
}