2023-08-15 12:23:17 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2023-04-27 10:13:38 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
2024-01-17 18:29:28 +03:00
|
|
|
import '../../app/shortcuts.dart';
|
2023-04-27 10:13:38 +03:00
|
|
|
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-04-27 10:13:38 +03:00
|
|
|
import '../models.dart';
|
|
|
|
import '../state.dart';
|
|
|
|
import 'actions.dart';
|
2023-08-23 16:53:30 +03:00
|
|
|
import 'cert_info_view.dart';
|
2023-04-27 10:13:38 +03:00
|
|
|
|
|
|
|
class SlotDialog extends ConsumerWidget {
|
|
|
|
final SlotId pivSlot;
|
2023-06-13 15:33:23 +03:00
|
|
|
const SlotDialog(this.pivSlot, {super.key});
|
2023-04-27 10:13:38 +03:00
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
|
|
|
|
final l10n = AppLocalizations.of(context)!;
|
|
|
|
final textTheme = Theme.of(context).textTheme;
|
2023-06-15 18:39:17 +03:00
|
|
|
// This is what ListTile uses for subtitle
|
|
|
|
final subtitleStyle = textTheme.bodyMedium!.copyWith(
|
|
|
|
color: textTheme.bodySmall!.color,
|
|
|
|
);
|
2023-04-27 10:13:38 +03:00
|
|
|
|
2023-06-13 15:33:23 +03:00
|
|
|
final pivState = ref.watch(pivStateProvider(node.path)).valueOrNull;
|
2023-04-27 10:13:38 +03:00
|
|
|
final slotData = ref.watch(pivSlotsProvider(node.path).select((value) =>
|
|
|
|
value.whenOrNull(
|
|
|
|
data: (data) =>
|
|
|
|
data.firstWhere((element) => element.slot == pivSlot))));
|
|
|
|
|
2023-06-13 15:33:23 +03:00
|
|
|
if (pivState == null || slotData == null) {
|
2023-04-27 10:13:38 +03:00
|
|
|
return const FsDialog(child: CircularProgressIndicator());
|
|
|
|
}
|
|
|
|
|
|
|
|
final certInfo = slotData.certInfo;
|
2024-01-18 16:46:15 +03:00
|
|
|
return PivActions(
|
|
|
|
devicePath: node.path,
|
|
|
|
pivState: pivState,
|
|
|
|
builder: (context) => ItemShortcuts(
|
|
|
|
item: slotData,
|
2024-01-17 18:29:28 +03:00
|
|
|
child: FocusScope(
|
|
|
|
autofocus: true,
|
|
|
|
child: FsDialog(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 48, bottom: 16),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
pivSlot.getDisplayName(l10n),
|
|
|
|
style: textTheme.headlineSmall,
|
|
|
|
softWrap: true,
|
|
|
|
textAlign: TextAlign.center,
|
2023-04-27 10:13:38 +03:00
|
|
|
),
|
2024-01-17 18:29:28 +03:00
|
|
|
if (certInfo != null) ...[
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
child: CertInfoTable(certInfo),
|
2023-04-27 10:13:38 +03:00
|
|
|
),
|
2024-01-17 18:29:28 +03:00
|
|
|
] else ...[
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
|
|
child: Text(
|
|
|
|
l10n.l_no_certificate,
|
|
|
|
softWrap: true,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: subtitleStyle,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
],
|
2023-04-27 10:13:38 +03:00
|
|
|
],
|
2024-01-17 18:29:28 +03:00
|
|
|
),
|
|
|
|
),
|
|
|
|
ActionListSection.fromMenuActions(
|
|
|
|
context,
|
|
|
|
l10n.s_actions,
|
|
|
|
actions: buildSlotActions(slotData, l10n),
|
2023-04-27 10:13:38 +03:00
|
|
|
),
|
2024-01-17 18:29:28 +03:00
|
|
|
],
|
|
|
|
),
|
2023-04-27 10:13:38 +03:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|