From efe0d1319d4ca8ce007c0fbefb391cba0657b578 Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Tue, 20 Dec 2022 16:07:16 +0100 Subject: [PATCH] Delay showing CircularProgressIndicators. --- lib/app/views/app_loading_screen.dart | 31 -------------- lib/app/views/app_page.dart | 47 ++++++++++++--------- lib/app/views/main_page.dart | 1 + lib/app/views/message_page.dart | 3 ++ lib/desktop/init.dart | 7 +-- lib/fido/views/fido_screen.dart | 4 +- lib/fido/views/unlocked_page.dart | 1 + lib/management/views/management_screen.dart | 8 +++- lib/oath/views/oath_screen.dart | 14 +++--- 9 files changed, 48 insertions(+), 68 deletions(-) delete mode 100755 lib/app/views/app_loading_screen.dart diff --git a/lib/app/views/app_loading_screen.dart b/lib/app/views/app_loading_screen.dart deleted file mode 100755 index a24fd742..00000000 --- a/lib/app/views/app_loading_screen.dart +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2022 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. - */ - -import 'package:flutter/material.dart'; - -class AppLoadingScreen extends StatelessWidget { - const AppLoadingScreen({super.key}); - - @override - Widget build(BuildContext context) { - return Column( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - Center(child: CircularProgressIndicator()), - ], - ); - } -} diff --git a/lib/app/views/app_page.dart b/lib/app/views/app_page.dart index 7ed719b4..3c32a6ca 100755 --- a/lib/app/views/app_page.dart +++ b/lib/app/views/app_page.dart @@ -16,6 +16,7 @@ import 'package:flutter/material.dart'; +import '../../widgets/delayed_visibility.dart'; import 'device_button.dart'; import 'keys.dart'; import 'main_drawer.dart'; @@ -27,6 +28,7 @@ class AppPage extends StatelessWidget { final List keyActions; final bool centered; final Widget Function(List)? actionButtonBuilder; + final bool delayedContent; const AppPage({ super.key, this.title, @@ -35,6 +37,7 @@ class AppPage extends StatelessWidget { this.keyActions = const [], this.centered = false, this.actionButtonBuilder, + this.delayedContent = false, }); @override @@ -65,30 +68,36 @@ class AppPage extends StatelessWidget { ); Widget _buildScrollView() { + final content = Column( + children: [ + child, + if (actions.isNotEmpty) + Align( + alignment: centered ? Alignment.center : Alignment.centerLeft, + child: Padding( + padding: + const EdgeInsets.symmetric(vertical: 16.0, horizontal: 18.0), + child: Wrap( + spacing: 4, + runSpacing: 4, + children: actions, + ), + ), + ), + ], + ); return SingleChildScrollView( child: SafeArea( child: Center( child: SizedBox( width: 700, - child: Column( - children: [ - child, - if (actions.isNotEmpty) - Align( - alignment: - centered ? Alignment.center : Alignment.centerLeft, - child: Padding( - padding: const EdgeInsets.symmetric( - vertical: 16.0, horizontal: 18.0), - child: Wrap( - spacing: 4, - runSpacing: 4, - children: actions, - ), - ), - ), - ], - ), + child: delayedContent + ? DelayedVisibility( + key: GlobalKey(), // Ensure we reset the delay on rebuild + delay: const Duration(milliseconds: 400), + child: content, + ) + : content, ), ), ), diff --git a/lib/app/views/main_page.dart b/lib/app/views/main_page.dart index 40a7aee6..4efc7c5c 100755 --- a/lib/app/views/main_page.dart +++ b/lib/app/views/main_page.dart @@ -104,6 +104,7 @@ class MainPage extends ConsumerWidget { ); } else { return MessagePage( + delayedContent: true, graphic: noKeyImage, message: 'Insert your YubiKey', ); diff --git a/lib/app/views/message_page.dart b/lib/app/views/message_page.dart index 71ae4ce8..682e2762 100755 --- a/lib/app/views/message_page.dart +++ b/lib/app/views/message_page.dart @@ -26,6 +26,7 @@ class MessagePage extends StatelessWidget { final List actions; final List keyActions; final Widget Function(List keyActions)? actionButtonBuilder; + final bool delayedContent; const MessagePage({ super.key, @@ -36,6 +37,7 @@ class MessagePage extends StatelessWidget { this.actions = const [], this.keyActions = const [], this.actionButtonBuilder, + this.delayedContent = false, }); @override @@ -45,6 +47,7 @@ class MessagePage extends StatelessWidget { actions: actions, keyActions: keyActions, actionButtonBuilder: actionButtonBuilder, + delayedContent: delayedContent, child: Padding( padding: const EdgeInsets.all(8.0), child: Column( diff --git a/lib/desktop/init.dart b/lib/desktop/init.dart index 5b088fcc..dd3d0825 100755 --- a/lib/desktop/init.dart +++ b/lib/desktop/init.dart @@ -40,7 +40,6 @@ import '../app/models.dart'; import '../app/state.dart'; import '../management/state.dart'; import '../version.dart'; -import '../widgets/delayed_visibility.dart'; import 'fido/state.dart'; import 'management/state.dart'; import 'oath/state.dart'; @@ -280,10 +279,8 @@ class _HelperWaiterState extends ConsumerState<_HelperWaiter> { ); } else { return const MessagePage( - graphic: DelayedVisibility( - delay: Duration(seconds: 1), - child: CircularProgressIndicator(), - ), + delayedContent: true, + graphic: CircularProgressIndicator(), ); } } diff --git a/lib/fido/views/fido_screen.dart b/lib/fido/views/fido_screen.dart index c45fff8a..aa30a776 100755 --- a/lib/fido/views/fido_screen.dart +++ b/lib/fido/views/fido_screen.dart @@ -20,7 +20,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../app/models.dart'; import '../../app/views/app_failure_page.dart'; -import '../../app/views/app_loading_screen.dart'; import '../../app/views/app_page.dart'; import '../../app/views/graphics.dart'; import '../../app/views/message_page.dart'; @@ -39,7 +38,8 @@ class FidoScreen extends ConsumerWidget { loading: () => AppPage( title: Text(AppLocalizations.of(context)!.fido_webauthn), centered: true, - child: const AppLoadingScreen(), + delayedContent: true, + child: const CircularProgressIndicator(), ), error: (error, _) { final supported = deviceData diff --git a/lib/fido/views/unlocked_page.dart b/lib/fido/views/unlocked_page.dart index b56caa48..a4802ce3 100755 --- a/lib/fido/views/unlocked_page.dart +++ b/lib/fido/views/unlocked_page.dart @@ -169,6 +169,7 @@ class FidoUnlockedPage extends ConsumerWidget { Widget _buildLoadingPage(BuildContext context) => AppPage( title: Text(AppLocalizations.of(context)!.fido_webauthn), centered: true, + delayedContent: true, child: const CircularProgressIndicator(), ); diff --git a/lib/management/views/management_screen.dart b/lib/management/views/management_screen.dart index 14c6ad16..1c8f39a0 100755 --- a/lib/management/views/management_screen.dart +++ b/lib/management/views/management_screen.dart @@ -21,9 +21,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../app/message.dart'; import '../../app/models.dart'; -import '../../app/views/app_loading_screen.dart'; import '../../core/models.dart'; import '../../widgets/custom_icons.dart'; +import '../../widgets/delayed_visibility.dart'; import '../../widgets/responsive_dialog.dart'; import '../models.dart'; import '../state.dart'; @@ -269,7 +269,11 @@ class _ManagementScreenState extends ConsumerState { final child = ref .watch(managementStateProvider(widget.deviceData.node.path)) .when( - loading: () => const AppLoadingScreen(), + loading: () => const Center( + child: DelayedVisibility( + delay: Duration(milliseconds: 200), + child: CircularProgressIndicator(), + )), error: (error, _) => Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, diff --git a/lib/oath/views/oath_screen.dart b/lib/oath/views/oath_screen.dart index 7c5eb840..99c87b6b 100755 --- a/lib/oath/views/oath_screen.dart +++ b/lib/oath/views/oath_screen.dart @@ -20,14 +20,12 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:yubico_authenticator/widgets/delayed_visibility.dart'; import '../../app/message.dart'; import '../../app/models.dart'; import '../../app/shortcuts.dart'; import '../../app/state.dart'; import '../../app/views/app_failure_page.dart'; -import '../../app/views/app_loading_screen.dart'; import '../../app/views/app_page.dart'; import '../../app/views/graphics.dart'; import '../../app/views/message_page.dart'; @@ -49,10 +47,10 @@ class OathScreen extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { return ref.watch(oathStateProvider(devicePath)).when( - loading: () => AppPage( + loading: () => MessagePage( title: Text(AppLocalizations.of(context)!.oath_authenticator), - centered: true, - child: const AppLoadingScreen(), + graphic: const CircularProgressIndicator(), + delayedContent: true, ), error: (error, _) => AppFailurePage( title: Text(AppLocalizations.of(context)!.oath_authenticator), @@ -204,6 +202,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> { used: numCreds ?? 0, ), centered: numCreds == null, + delayedContent: numCreds == null, child: numCreds != null ? Consumer( builder: (context, ref, _) { @@ -212,10 +211,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> { ); }, ) - : const DelayedVisibility( - delay: Duration(milliseconds: 200), - child: CircularProgressIndicator(), - ), + : const CircularProgressIndicator(), ), ); }