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

99 lines
3.3 KiB
Dart
Raw Normal View History

2023-05-04 17:20:50 +03:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../app/message.dart';
import '../../app/shortcuts.dart';
import '../../app/state.dart';
import '../../app/views/fs_dialog.dart';
2023-06-09 15:46:16 +03:00
import '../../app/views/action_list.dart';
2023-10-06 11:49:01 +03:00
import '../../core/state.dart';
import '../features.dart' as features;
2023-05-04 17:20:50 +03:00
import '../models.dart';
2023-06-15 18:39:17 +03:00
import 'actions.dart';
2023-05-04 17:20:50 +03:00
import 'delete_credential_dialog.dart';
class CredentialDialog extends ConsumerWidget {
final FidoCredential credential;
const CredentialDialog(this.credential, {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);
2023-05-04 17:20:50 +03:00
return Actions(
actions: {
2023-10-06 11:49:01 +03:00
if (hasFeature(features.credentialsDelete))
DeleteIntent: CallbackAction<DeleteIntent>(onInvoke: (_) async {
final withContext = ref.read(withContextProvider);
final bool? deleted =
await ref.read(withContextProvider)((context) async =>
await showBlurDialog(
context: context,
builder: (context) => DeleteCredentialDialog(
node.path,
credential,
),
) ??
false);
2023-05-04 17:20:50 +03:00
2023-10-06 11:49:01 +03:00
// Pop the account dialog if deleted
if (deleted == true) {
await withContext((context) async {
Navigator.of(context).pop();
});
}
return deleted;
}),
2023-05-04 17:20:50 +03:00
},
child: FocusScope(
autofocus: true,
child: FsDialog(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 48, bottom: 32),
child: Column(
children: [
Text(
credential.userName,
style: Theme.of(context).textTheme.headlineSmall,
softWrap: true,
textAlign: TextAlign.center,
),
Text(
credential.rpId,
softWrap: true,
textAlign: TextAlign.center,
// This is what ListTile uses for subtitle
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).textTheme.bodySmall!.color,
),
),
const SizedBox(height: 16),
const Icon(Icons.person, size: 72),
],
),
),
2023-06-15 18:39:17 +03:00
ActionListSection.fromMenuActions(
context,
2023-06-09 15:46:16 +03:00
l10n.s_actions,
2023-06-15 18:39:17 +03:00
actions: buildCredentialActions(l10n),
2023-06-09 15:46:16 +03:00
),
2023-05-04 17:20:50 +03:00
],
),
),
),
);
}
}