Files
pipelines/app/lib/features/templates/ui/templates_failure.dart
T
alan 1db273894c Remove Cupertino template branches
Keep the Material-only template implementation and narrow its tests to the runtime path. Retain public Cupertino parameters for compatibility while removing unreachable hosts, widgets, and test variants.
2026-11-11 02:53:23 +00:00

101 lines
2.6 KiB
Dart

import 'package:flutter/material.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(
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: Theme.of(context).colorScheme.error),
),
),
_retryButton(
buttonKey: templatesBannerRetryKey,
retrying: retrying,
onRetry: onRetry,
),
],
),
);
}
}
Widget _retryButton({
required Key buttonKey,
required bool retrying,
required VoidCallback onRetry,
}) {
final onPressed = retrying ? null : onRetry;
return TextButton(
key: buttonKey,
onPressed: onPressed,
child: const Text('Retry'),
);
}