119 lines
3.1 KiB
Dart
119 lines
3.1 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/host.dart';
|
|
|
|
const templatesErrorKey = ValueKey<String>('templates-error');
|
|
const templatesRetryKey = ValueKey<String>('templates-retry');
|
|
const templatesErrorBannerKey = ValueKey<String>('templates-error-banner');
|
|
const templatesBannerRetryKey = ValueKey<String>('templates-banner-retry');
|
|
|
|
/// A refusal for a catalogue that never loaded: the whole body is the failure.
|
|
class TemplatesFailureState extends StatelessWidget {
|
|
const TemplatesFailureState({
|
|
super.key,
|
|
required this.message,
|
|
required this.retrying,
|
|
required this.onRetry,
|
|
});
|
|
|
|
final String message;
|
|
final bool retrying;
|
|
final VoidCallback onRetry;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
key: templatesErrorKey,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Semantics(
|
|
liveRegion: true,
|
|
child: Text(message, textAlign: TextAlign.center),
|
|
),
|
|
const SizedBox(height: 8),
|
|
_retryButton(
|
|
context,
|
|
buttonKey: templatesRetryKey,
|
|
retrying: retrying,
|
|
onRetry: onRetry,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// A refused refresh, shown above whichever body stays visible.
|
|
///
|
|
/// The screen renders this above both the catalogue and an open template, so a
|
|
/// failed refresh can never be silent while a template is selected.
|
|
class TemplatesFailureBanner extends StatelessWidget {
|
|
const TemplatesFailureBanner({
|
|
super.key,
|
|
required this.message,
|
|
required this.retrying,
|
|
required this.onRetry,
|
|
});
|
|
|
|
final String message;
|
|
final bool retrying;
|
|
final VoidCallback onRetry;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
key: templatesErrorBannerKey,
|
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Semantics(
|
|
liveRegion: true,
|
|
child: Text(
|
|
message,
|
|
style: TextStyle(
|
|
color: usesCupertinoHost(context)
|
|
? CupertinoColors.systemRed.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.error,
|
|
),
|
|
),
|
|
),
|
|
_retryButton(
|
|
context,
|
|
buttonKey: templatesBannerRetryKey,
|
|
retrying: retrying,
|
|
onRetry: onRetry,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget _retryButton(
|
|
BuildContext context, {
|
|
required Key buttonKey,
|
|
required bool retrying,
|
|
required VoidCallback onRetry,
|
|
}) {
|
|
final onPressed = retrying ? null : onRetry;
|
|
if (usesCupertinoHost(context)) {
|
|
return CupertinoButton(
|
|
key: buttonKey,
|
|
padding: EdgeInsets.zero,
|
|
onPressed: onPressed,
|
|
child: const Text('Retry'),
|
|
);
|
|
}
|
|
return TextButton(
|
|
key: buttonKey,
|
|
onPressed: onPressed,
|
|
child: const Text('Retry'),
|
|
);
|
|
}
|