import 'package:flutter/material.dart'; /// 错误状态视图,提供重试按钮。 class ErrorView extends StatelessWidget { const ErrorView({ super.key, this.message = '加载失败,请重试', this.onRetry, }); final String message; final VoidCallback? onRetry; @override Widget build(BuildContext context) { return Center( child: Padding( padding: const EdgeInsets.all(32), child: Column( mainAxisSize: MainAxisSize.min, children: [ Icon( Icons.error_outline, size: 56, color: Theme.of(context).colorScheme.error, ), const SizedBox(height: 16), Text( message, style: Theme.of(context).textTheme.bodyMedium?.copyWith( color: Theme.of(context).colorScheme.onSurfaceVariant, ), textAlign: TextAlign.center, ), if (onRetry != null) ...[ const SizedBox(height: 24), FilledButton.tonal( onPressed: onRetry, child: const Text('重试'), ), ], ], ), ), ); } }