Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'app_surface_styles.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;
- final imageHeight =
- screenHeight * 0.32 > 420 ? 420.0 : screenHeight * 0.32;
- final buttonBackground = Theme.of(context).scaffoldBackgroundColor;
- 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,
- 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),
- Material(
- color: Colors.transparent,
- child: InkWell(
- onTap: onRetry,
- borderRadius: BorderRadius.circular(14),
- splashColor: Colors.transparent,
- highlightColor: Colors.transparent,
- child: Container(
- padding: const EdgeInsets.symmetric(
- horizontal: 22,
- vertical: 12,
- ),
- decoration: AppSurfaceStyles.card(
- context,
- backgroundColor: buttonBackground,
- radius: 14,
- isHighlighted: true,
- ),
- child: Text(
- 'Retry',
- style: Theme.of(context).textTheme.titleMedium?.copyWith(
- fontWeight: FontWeight.w600,
- color: colorScheme.primary,
- ),
- ),
- ),
- ),
- ),
- ],
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment