Delay showing CircularProgressIndicators.

This commit is contained in:
Dain Nilsson 2022-12-20 16:07:16 +01:00
parent 230d7a05b7
commit efe0d1319d
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
9 changed files with 48 additions and 68 deletions

View File

@ -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()),
],
);
}
}

View File

@ -16,6 +16,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../widgets/delayed_visibility.dart';
import 'device_button.dart'; import 'device_button.dart';
import 'keys.dart'; import 'keys.dart';
import 'main_drawer.dart'; import 'main_drawer.dart';
@ -27,6 +28,7 @@ class AppPage extends StatelessWidget {
final List<PopupMenuEntry> keyActions; final List<PopupMenuEntry> keyActions;
final bool centered; final bool centered;
final Widget Function(List<PopupMenuEntry>)? actionButtonBuilder; final Widget Function(List<PopupMenuEntry>)? actionButtonBuilder;
final bool delayedContent;
const AppPage({ const AppPage({
super.key, super.key,
this.title, this.title,
@ -35,6 +37,7 @@ class AppPage extends StatelessWidget {
this.keyActions = const [], this.keyActions = const [],
this.centered = false, this.centered = false,
this.actionButtonBuilder, this.actionButtonBuilder,
this.delayedContent = false,
}); });
@override @override
@ -65,30 +68,36 @@ class AppPage extends StatelessWidget {
); );
Widget _buildScrollView() { 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( return SingleChildScrollView(
child: SafeArea( child: SafeArea(
child: Center( child: Center(
child: SizedBox( child: SizedBox(
width: 700, width: 700,
child: Column( child: delayedContent
children: [ ? DelayedVisibility(
child, key: GlobalKey(), // Ensure we reset the delay on rebuild
if (actions.isNotEmpty) delay: const Duration(milliseconds: 400),
Align( child: content,
alignment: )
centered ? Alignment.center : Alignment.centerLeft, : content,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 16.0, horizontal: 18.0),
child: Wrap(
spacing: 4,
runSpacing: 4,
children: actions,
),
),
),
],
),
), ),
), ),
), ),

View File

@ -104,6 +104,7 @@ class MainPage extends ConsumerWidget {
); );
} else { } else {
return MessagePage( return MessagePage(
delayedContent: true,
graphic: noKeyImage, graphic: noKeyImage,
message: 'Insert your YubiKey', message: 'Insert your YubiKey',
); );

View File

@ -26,6 +26,7 @@ class MessagePage extends StatelessWidget {
final List<Widget> actions; final List<Widget> actions;
final List<PopupMenuEntry> keyActions; final List<PopupMenuEntry> keyActions;
final Widget Function(List<PopupMenuEntry> keyActions)? actionButtonBuilder; final Widget Function(List<PopupMenuEntry> keyActions)? actionButtonBuilder;
final bool delayedContent;
const MessagePage({ const MessagePage({
super.key, super.key,
@ -36,6 +37,7 @@ class MessagePage extends StatelessWidget {
this.actions = const [], this.actions = const [],
this.keyActions = const [], this.keyActions = const [],
this.actionButtonBuilder, this.actionButtonBuilder,
this.delayedContent = false,
}); });
@override @override
@ -45,6 +47,7 @@ class MessagePage extends StatelessWidget {
actions: actions, actions: actions,
keyActions: keyActions, keyActions: keyActions,
actionButtonBuilder: actionButtonBuilder, actionButtonBuilder: actionButtonBuilder,
delayedContent: delayedContent,
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Column( child: Column(

View File

@ -40,7 +40,6 @@ import '../app/models.dart';
import '../app/state.dart'; import '../app/state.dart';
import '../management/state.dart'; import '../management/state.dart';
import '../version.dart'; import '../version.dart';
import '../widgets/delayed_visibility.dart';
import 'fido/state.dart'; import 'fido/state.dart';
import 'management/state.dart'; import 'management/state.dart';
import 'oath/state.dart'; import 'oath/state.dart';
@ -280,10 +279,8 @@ class _HelperWaiterState extends ConsumerState<_HelperWaiter> {
); );
} else { } else {
return const MessagePage( return const MessagePage(
graphic: DelayedVisibility( delayedContent: true,
delay: Duration(seconds: 1), graphic: CircularProgressIndicator(),
child: CircularProgressIndicator(),
),
); );
} }
} }

View File

@ -20,7 +20,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../app/models.dart'; import '../../app/models.dart';
import '../../app/views/app_failure_page.dart'; import '../../app/views/app_failure_page.dart';
import '../../app/views/app_loading_screen.dart';
import '../../app/views/app_page.dart'; import '../../app/views/app_page.dart';
import '../../app/views/graphics.dart'; import '../../app/views/graphics.dart';
import '../../app/views/message_page.dart'; import '../../app/views/message_page.dart';
@ -39,7 +38,8 @@ class FidoScreen extends ConsumerWidget {
loading: () => AppPage( loading: () => AppPage(
title: Text(AppLocalizations.of(context)!.fido_webauthn), title: Text(AppLocalizations.of(context)!.fido_webauthn),
centered: true, centered: true,
child: const AppLoadingScreen(), delayedContent: true,
child: const CircularProgressIndicator(),
), ),
error: (error, _) { error: (error, _) {
final supported = deviceData final supported = deviceData

View File

@ -169,6 +169,7 @@ class FidoUnlockedPage extends ConsumerWidget {
Widget _buildLoadingPage(BuildContext context) => AppPage( Widget _buildLoadingPage(BuildContext context) => AppPage(
title: Text(AppLocalizations.of(context)!.fido_webauthn), title: Text(AppLocalizations.of(context)!.fido_webauthn),
centered: true, centered: true,
delayedContent: true,
child: const CircularProgressIndicator(), child: const CircularProgressIndicator(),
); );

View File

@ -21,9 +21,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../app/message.dart'; import '../../app/message.dart';
import '../../app/models.dart'; import '../../app/models.dart';
import '../../app/views/app_loading_screen.dart';
import '../../core/models.dart'; import '../../core/models.dart';
import '../../widgets/custom_icons.dart'; import '../../widgets/custom_icons.dart';
import '../../widgets/delayed_visibility.dart';
import '../../widgets/responsive_dialog.dart'; import '../../widgets/responsive_dialog.dart';
import '../models.dart'; import '../models.dart';
import '../state.dart'; import '../state.dart';
@ -269,7 +269,11 @@ class _ManagementScreenState extends ConsumerState<ManagementScreen> {
final child = ref final child = ref
.watch(managementStateProvider(widget.deviceData.node.path)) .watch(managementStateProvider(widget.deviceData.node.path))
.when( .when(
loading: () => const AppLoadingScreen(), loading: () => const Center(
child: DelayedVisibility(
delay: Duration(milliseconds: 200),
child: CircularProgressIndicator(),
)),
error: (error, _) => Center( error: (error, _) => Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,

View File

@ -20,14 +20,12 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yubico_authenticator/widgets/delayed_visibility.dart';
import '../../app/message.dart'; import '../../app/message.dart';
import '../../app/models.dart'; import '../../app/models.dart';
import '../../app/shortcuts.dart'; import '../../app/shortcuts.dart';
import '../../app/state.dart'; import '../../app/state.dart';
import '../../app/views/app_failure_page.dart'; import '../../app/views/app_failure_page.dart';
import '../../app/views/app_loading_screen.dart';
import '../../app/views/app_page.dart'; import '../../app/views/app_page.dart';
import '../../app/views/graphics.dart'; import '../../app/views/graphics.dart';
import '../../app/views/message_page.dart'; import '../../app/views/message_page.dart';
@ -49,10 +47,10 @@ class OathScreen extends ConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
return ref.watch(oathStateProvider(devicePath)).when( return ref.watch(oathStateProvider(devicePath)).when(
loading: () => AppPage( loading: () => MessagePage(
title: Text(AppLocalizations.of(context)!.oath_authenticator), title: Text(AppLocalizations.of(context)!.oath_authenticator),
centered: true, graphic: const CircularProgressIndicator(),
child: const AppLoadingScreen(), delayedContent: true,
), ),
error: (error, _) => AppFailurePage( error: (error, _) => AppFailurePage(
title: Text(AppLocalizations.of(context)!.oath_authenticator), title: Text(AppLocalizations.of(context)!.oath_authenticator),
@ -204,6 +202,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
used: numCreds ?? 0, used: numCreds ?? 0,
), ),
centered: numCreds == null, centered: numCreds == null,
delayedContent: numCreds == null,
child: numCreds != null child: numCreds != null
? Consumer( ? Consumer(
builder: (context, ref, _) { builder: (context, ref, _) {
@ -212,10 +211,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
); );
}, },
) )
: const DelayedVisibility( : const CircularProgressIndicator(),
delay: Duration(milliseconds: 200),
child: CircularProgressIndicator(),
),
), ),
); );
} }