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';
|
2024-03-08 11:30:47 +03:00
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
2023-05-04 17:20:50 +03:00
|
|
|
|
|
|
|
import '../../app/shortcuts.dart';
|
|
|
|
import '../../app/state.dart';
|
2023-06-09 15:46:16 +03:00
|
|
|
import '../../app/views/action_list.dart';
|
2023-11-27 13:41:05 +03:00
|
|
|
import '../../app/views/fs_dialog.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';
|
2024-03-28 11:58:47 +03:00
|
|
|
import 'credential_info_view.dart';
|
2023-05-04 17:20:50 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2024-01-18 16:46:15 +03:00
|
|
|
return FidoActions(
|
|
|
|
devicePath: node.path,
|
|
|
|
actions: (context) => {
|
2023-10-06 11:49:01 +03:00
|
|
|
if (hasFeature(features.credentialsDelete))
|
2024-01-17 18:29:28 +03:00
|
|
|
DeleteIntent<FidoCredential>:
|
|
|
|
CallbackAction<DeleteIntent<FidoCredential>>(
|
|
|
|
onInvoke: (intent) async {
|
2024-01-18 16:46:15 +03:00
|
|
|
final deleted =
|
|
|
|
await (Actions.invoke(context, intent) as Future<dynamic>?);
|
2023-10-06 11:49:01 +03:00
|
|
|
// Pop the account dialog if deleted
|
|
|
|
if (deleted == true) {
|
2024-01-18 16:46:15 +03:00
|
|
|
await ref.read(withContextProvider)((context) async {
|
2023-10-06 11:49:01 +03:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return deleted;
|
|
|
|
}),
|
2023-05-04 17:20:50 +03:00
|
|
|
},
|
2024-01-18 16:46:15 +03:00
|
|
|
builder: (context) => ItemShortcuts(
|
|
|
|
item: credential,
|
2024-01-17 18:29:28 +03:00
|
|
|
child: FocusScope(
|
|
|
|
autofocus: true,
|
|
|
|
child: FsDialog(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
2024-03-28 11:58:47 +03:00
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 48, bottom: 32, left: 16, right: 16),
|
2024-01-17 18:29:28 +03:00
|
|
|
child: Column(
|
|
|
|
children: [
|
2024-04-25 16:26:33 +03:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
child: Icon(
|
|
|
|
Symbols.passkey,
|
|
|
|
size: 100,
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
),
|
2024-01-17 18:29:28 +03:00
|
|
|
),
|
2024-03-28 11:58:47 +03:00
|
|
|
CredentialInfoTable(credential),
|
2024-01-17 18:29:28 +03:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ActionListSection.fromMenuActions(
|
|
|
|
context,
|
|
|
|
l10n.s_actions,
|
|
|
|
actions: buildCredentialActions(credential, l10n),
|
2023-05-04 17:20:50 +03:00
|
|
|
),
|
2024-01-17 18:29:28 +03:00
|
|
|
],
|
|
|
|
),
|
2023-05-04 17:20:50 +03:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|