material static method

Widget material({
  1. required BuildContext context,
  2. required Exception error,
  3. required VoidCallback onRetry,
  4. String? title,
  5. String? message,
  6. IconData? icon,
  7. Color? iconColor,
  8. String? retryButtonText,
})

Creates a Material Design style error widget with full details

Best suited for first page errors where you have full screen space

Implementation

static Widget material({
  required BuildContext context,
  required Exception error,
  required VoidCallback onRetry,
  String? title,
  String? message,
  IconData? icon,
  Color? iconColor,
  String? retryButtonText,
}) {
  return Center(
    child: Padding(
      padding: const EdgeInsets.all(24.0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(
            icon ?? Icons.error_outline,
            color: iconColor ?? Colors.red,
            size: 64,
          ),
          const SizedBox(height: 24),
          Text(
            title ?? 'Something went wrong',
            style: Theme.of(context).textTheme.headlineSmall?.copyWith(
                  fontWeight: FontWeight.bold,
                ),
            textAlign: TextAlign.center,
          ),
          const SizedBox(height: 12),
          Text(
            message ?? error.toString(),
            textAlign: TextAlign.center,
            style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                  color: Colors.grey[600],
                ),
          ),
          const SizedBox(height: 24),
          ElevatedButton.icon(
            onPressed: onRetry,
            icon: const Icon(Icons.refresh),
            label: Text(retryButtonText ?? 'Try Again'),
            style: ElevatedButton.styleFrom(
              padding: const EdgeInsets.symmetric(
                horizontal: 32,
                vertical: 16,
              ),
            ),
          ),
        ],
      ),
    ),
  );
}