generateErrorState static method
Implementation
static String generateErrorState() {
return '''
import 'package:flutter/material.dart';
class ErrorState extends StatelessWidget {
final String title;
final String message;
final VoidCallback? onRetry;
final String? retryText;
final IconData icon;
const ErrorState({
Key? key,
this.title = 'Oops! Something went wrong',
required this.message,
this.onRetry,
this.retryText,
this.icon = Icons.error_outline,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Center(
child: Padding(
padding: const EdgeInsets.all(40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(28),
decoration: BoxDecoration(
color: theme.colorScheme.errorContainer.withOpacity(0.3),
shape: BoxShape.circle,
),
child: Icon(
icon,
size: 72,
color: theme.colorScheme.error,
),
),
const SizedBox(height: 32),
Text(
title,
style: theme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onSurface,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
Text(
message,
style: theme.textTheme.bodyLarge?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
height: 1.5,
),
textAlign: TextAlign.center,
),
if (onRetry != null) ...[
const SizedBox(height: 32),
FilledButton.icon(
onPressed: onRetry,
icon: const Icon(Icons.refresh),
label: Text(retryText ?? 'Try Again'),
style: FilledButton.styleFrom(
backgroundColor: theme.colorScheme.error,
padding: const EdgeInsets.symmetric(
horizontal: 32,
vertical: 16,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
),
),
],
],
),
),
);
}
}
''';
}