107 lines
2.9 KiB
Dart
107 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../core/errors/failure.dart';
|
|
|
|
class ErrorView extends StatelessWidget {
|
|
const ErrorView({
|
|
super.key,
|
|
required this.message,
|
|
this.onRetry,
|
|
});
|
|
|
|
final String message;
|
|
final VoidCallback? onRetry;
|
|
|
|
factory ErrorView.fromFailure(Failure failure, {VoidCallback? onRetry}) {
|
|
return ErrorView(
|
|
message: failure.when(
|
|
server: (message, _, __) => message,
|
|
network: (message) => message,
|
|
unauthorized: (message) => message,
|
|
validation: (message, _) => message,
|
|
notFound: (message) => message,
|
|
cache: (message) => message,
|
|
unknown: (message) => message,
|
|
),
|
|
onRetry: onRetry,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.error_outline, size: 48, color: Theme.of(context).colorScheme.error),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
message,
|
|
textAlign: TextAlign.center,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
if (onRetry != null) ...[
|
|
const SizedBox(height: 16),
|
|
OutlinedButton.icon(
|
|
onPressed: onRetry,
|
|
icon: const Icon(Icons.refresh),
|
|
label: const Text('Retry'),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class EmptyStateView extends StatelessWidget {
|
|
const EmptyStateView({
|
|
super.key,
|
|
required this.title,
|
|
this.description,
|
|
this.icon = Icons.inbox_outlined,
|
|
this.action,
|
|
this.actionLabel,
|
|
});
|
|
|
|
final String title;
|
|
final String? description;
|
|
final IconData icon;
|
|
final VoidCallback? action;
|
|
final String? actionLabel;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(32),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(icon, size: 64, color: Theme.of(context).colorScheme.outline),
|
|
const SizedBox(height: 16),
|
|
Text(title, style: Theme.of(context).textTheme.titleLarge),
|
|
if (description != null) ...[
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
description!,
|
|
textAlign: TextAlign.center,
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
if (action != null && actionLabel != null) ...[
|
|
const SizedBox(height: 24),
|
|
ElevatedButton(onPressed: action, child: Text(actionLabel!)),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|