Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- class AppErrorState extends StatelessWidget {
- final String message;
- final VoidCallback? onRetry;
- final String? imageAssetPath;
- const AppErrorState({
- super.key,
- required this.message,
- this.onRetry,
- this.imageAssetPath,
- });
- @override
- Widget build(BuildContext context) {
- final colorScheme = Theme.of(context).colorScheme;
- final screenHeight = MediaQuery.of(context).size.height;
- // 🔥 Responsive height with max cap
- final imageHeight =
- screenHeight * 0.32 > 420 ? 420.0 : screenHeight * 0.32;
- return Center(
- child: Padding(
- padding: const EdgeInsets.all(24),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- if (imageAssetPath != null)
- Image.asset(
- imageAssetPath!,
- height: imageHeight,
- fit: BoxFit.contain,
- filterQuality: FilterQuality.high, // 👈 sharper image
- errorBuilder: (context, error, stackTrace) {
- return Icon(
- Icons.cloud_off,
- size: 72,
- color: colorScheme.outline,
- );
- },
- )
- else
- Icon(
- Icons.cloud_off,
- size: 72,
- color: colorScheme.outline,
- ),
- SizedBox(height: screenHeight * 0.025),
- Text(
- message,
- textAlign: TextAlign.center,
- style: Theme.of(context).textTheme.titleMedium,
- ),
- if (onRetry != null) ...[
- SizedBox(height: screenHeight * 0.025),
- ElevatedButton(
- onPressed: onRetry,
- child: const Text('Retry'),
- ),
- ],
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment