From fa05e725384ac22c7e6bc8e0a8719187084c67bb Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Wed, 10 Jan 2024 20:58:25 +0100 Subject: [PATCH] Separate "detailed view" from "key actions". --- lib/app/views/app_page.dart | 14 ++++++++++++-- lib/fido/views/unlocked_page.dart | 11 ++++++----- lib/otp/views/otp_screen.dart | 11 ++++++----- lib/piv/views/piv_screen.dart | 16 ++++++---------- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/lib/app/views/app_page.dart b/lib/app/views/app_page.dart index 37b7c7ec..8814bf6f 100755 --- a/lib/app/views/app_page.dart +++ b/lib/app/views/app_page.dart @@ -35,6 +35,7 @@ class AppPage extends StatelessWidget { final Widget? title; final Widget? child; final Widget Function(BuildContext context, bool expanded)? builder; + final Widget Function(BuildContext context)? detailViewBuilder; final List actions; final Widget Function(BuildContext context)? keyActionsBuilder; final bool keyActionsBadge; @@ -51,6 +52,7 @@ class AppPage extends StatelessWidget { this.actions = const [], this.centered = false, this.keyActionsBuilder, + this.detailViewBuilder, this.actionButtonBuilder, this.fileDropOverlay, this.onFileDropped, @@ -228,13 +230,21 @@ class AppPage extends StatelessWidget { body ]), )), - if (hasManage && keyActionsBuilder != null) + if (hasManage && + (detailViewBuilder != null || keyActionsBuilder != null)) SingleChildScrollView( child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8), child: SizedBox( width: 320, - child: keyActionsBuilder!(context), + child: Column( + children: [ + if (detailViewBuilder != null) + detailViewBuilder!(context), + if (keyActionsBuilder != null) + keyActionsBuilder!(context), + ], + ), ), ), ), diff --git a/lib/fido/views/unlocked_page.dart b/lib/fido/views/unlocked_page.dart index 64237e7f..5bc7d477 100755 --- a/lib/fido/views/unlocked_page.dart +++ b/lib/fido/views/unlocked_page.dart @@ -235,7 +235,7 @@ class _FidoUnlockedPageState extends ConsumerState { }, child: AppPage( title: Text(l10n.s_webauthn), - keyActionsBuilder: switch (selected) { + detailViewBuilder: switch (selected) { FidoCredential credential => (context) => _registerCredentialActions(credential, ref: ref, @@ -319,11 +319,12 @@ class _FidoUnlockedPageState extends ConsumerState { ], ), ), - _ => hasActions - ? (context) => fidoBuildActions( - context, widget.node, widget.state, nFingerprints) - : null + _ => null }, + keyActionsBuilder: hasActions + ? (context) => fidoBuildActions( + context, widget.node, widget.state, nFingerprints) + : null, keyActionsBadge: fidoShowActionsNotifier(widget.state), builder: (context, expanded) => Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/otp/views/otp_screen.dart b/lib/otp/views/otp_screen.dart index 45fdf391..473c564d 100644 --- a/lib/otp/views/otp_screen.dart +++ b/lib/otp/views/otp_screen.dart @@ -80,7 +80,7 @@ class _OtpScreenState extends ConsumerState { }, child: AppPage( title: Text(l10n.s_slots), - keyActionsBuilder: selected != null + detailViewBuilder: selected != null ? (context) => registerOtpActions( widget.devicePath, selected, @@ -125,10 +125,11 @@ class _OtpScreenState extends ConsumerState { ], ), ) - : (hasFeature(features.actions) - ? (context) => otpBuildActions( - context, widget.devicePath, otpState, ref) - : null), + : null, + keyActionsBuilder: hasFeature(features.actions) + ? (context) => + otpBuildActions(context, widget.devicePath, otpState, ref) + : null, builder: (context, expanded) { // De-select if window is resized to be non-expanded. if (!expanded) { diff --git a/lib/piv/views/piv_screen.dart b/lib/piv/views/piv_screen.dart index 7a8ca58f..d9be20c5 100644 --- a/lib/piv/views/piv_screen.dart +++ b/lib/piv/views/piv_screen.dart @@ -92,8 +92,7 @@ class _PivScreenState extends ConsumerState { }, child: AppPage( title: Text(l10n.s_certificates), - keyActionsBuilder: selected != null - // TODO: Reuse slot dialog + detailViewBuilder: selected != null ? (context) => registerPivActions( widget.devicePath, pivState, @@ -133,17 +132,14 @@ class _PivScreenState extends ConsumerState { actions: buildSlotActions( selected.certInfo != null, l10n), ), - if (hasFeature(features.actions)) ...[ - pivBuildActions( - context, widget.devicePath, pivState, ref), - ], ], ), ) - : (hasFeature(features.actions) - ? (context) => pivBuildActions( - context, widget.devicePath, pivState, ref) - : null), + : null, + keyActionsBuilder: hasFeature(features.actions) + ? (context) => pivBuildActions( + context, widget.devicePath, pivState, ref) + : null, builder: (context, expanded) { // De-select if window is resized to be non-expanded. if (!expanded) {