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

105 lines
3.7 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
2024-03-08 11:30:47 +03:00
import 'package:material_symbols_icons/symbols.dart';
import '../../app/message.dart';
import '../../app/shortcuts.dart';
import '../../app/state.dart';
2023-06-09 15:46:16 +03:00
import '../../app/views/action_list.dart';
import '../../app/views/fs_dialog.dart';
2023-10-06 11:49:01 +03:00
import '../../core/state.dart';
import '../features.dart' as features;
import '../models.dart';
2023-06-15 18:39:17 +03:00
import 'actions.dart';
class FingerprintDialog extends ConsumerWidget {
final Fingerprint fingerprint;
const FingerprintDialog(this.fingerprint, {super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
// TODO: Solve this in a cleaner way
final node = ref.watch(currentDeviceDataProvider).valueOrNull?.node;
if (node == null) {
// The rest of this method assumes there is a device, and will throw an exception if not.
// This will never be shown, as the dialog will be immediately closed
return const SizedBox();
}
2023-06-09 15:46:16 +03:00
final l10n = AppLocalizations.of(context)!;
2023-10-06 11:49:01 +03:00
final hasFeature = ref.watch(featureProvider);
return FidoActions(
devicePath: node.path,
actions: (context) => {
2023-10-06 11:49:01 +03:00
if (hasFeature(features.fingerprintsEdit))
EditIntent<Fingerprint>:
CallbackAction<EditIntent<Fingerprint>>(onInvoke: (intent) async {
final renamed =
await (Actions.invoke(context, intent) as Future<dynamic>?);
if (renamed is Fingerprint) {
2023-10-06 11:49:01 +03:00
// Replace the dialog with the renamed credential
await ref.read(withContextProvider)((context) async {
2023-10-06 11:49:01 +03:00
Navigator.of(context).pop();
await showBlurDialog(
context: context,
builder: (context) => FingerprintDialog(renamed),
2023-10-06 11:49:01 +03:00
);
});
}
return renamed;
}),
if (hasFeature(features.fingerprintsDelete))
DeleteIntent<Fingerprint>: CallbackAction<DeleteIntent<Fingerprint>>(
onInvoke: (intent) async {
final deleted =
await (Actions.invoke(context, intent) as Future<dynamic>?);
// Pop the fingerprint dialog if deleted
2023-10-06 11:49:01 +03:00
if (deleted == true) {
await ref.read(withContextProvider)((context) async {
2023-10-06 11:49:01 +03:00
Navigator.of(context).pop();
});
}
return deleted;
}),
},
builder: (context) => ItemShortcuts(
item: fingerprint,
child: FocusScope(
autofocus: true,
child: FsDialog(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 48, bottom: 32),
child: Column(
children: [
Text(
fingerprint.label,
style: Theme.of(context).textTheme.headlineSmall,
softWrap: true,
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
2024-04-25 16:26:33 +03:00
Icon(
Symbols.fingerprint,
size: 100,
color: Theme.of(context).colorScheme.onSurface,
),
],
),
),
ActionListSection.fromMenuActions(
context,
l10n.s_actions,
actions: buildFingerprintActions(fingerprint, l10n),
),
],
),
),
),
),
);
}
}