network_error_body.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'package:flutter/material.dart';
  2. import '../../../core/l10n/app_localizations.dart';
  3. import '../../../core/theme/app_colors.dart';
  4. /// 网络错误占位体(无 Scaffold/AppBar)
  5. /// 用于嵌入已有页面内容区,需要完整路由页面时使用 [NetworkErrorScreen]。
  6. class NetworkErrorBody extends StatelessWidget {
  7. const NetworkErrorBody({super.key, required this.onRetry});
  8. final VoidCallback onRetry;
  9. @override
  10. Widget build(BuildContext context) {
  11. final cs = Theme.of(context).colorScheme;
  12. final l10n = AppLocalizations.of(context)!;
  13. return Center(
  14. child: Padding(
  15. padding: const EdgeInsets.symmetric(horizontal: 40),
  16. child: Column(
  17. mainAxisSize: MainAxisSize.min,
  18. children: [
  19. Container(
  20. width: 100, height: 100,
  21. decoration: const BoxDecoration(color: Color(0xFFF2F2F2), shape: BoxShape.circle),
  22. child: const Icon(Icons.wifi_off_rounded, size: 52, color: Color(0xFFBBBBBB)),
  23. ),
  24. const SizedBox(height: 28),
  25. Text(l10n.pageLoadFailed, style: TextStyle(color: cs.onSurface, fontSize: 17, fontWeight: FontWeight.w600)),
  26. const SizedBox(height: 10),
  27. Text(
  28. l10n.networkConnectionError,
  29. textAlign: TextAlign.center,
  30. style: TextStyle(color: cs.onSurface.withAlpha(153), fontSize: 13, height: 1.5),
  31. ),
  32. const SizedBox(height: 36),
  33. SizedBox(
  34. width: double.infinity, height: 50,
  35. child: FilledButton.icon(
  36. onPressed: onRetry,
  37. style: FilledButton.styleFrom(
  38. backgroundColor: AppColors.brand,
  39. foregroundColor: Colors.black,
  40. shape: const StadiumBorder(),
  41. ),
  42. icon: const Icon(Icons.refresh_rounded, size: 18),
  43. label: Text(l10n.reload, style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w500)),
  44. ),
  45. ),
  46. ],
  47. ),
  48. ),
  49. );
  50. }
  51. }