loading_view.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import 'package:flutter/material.dart';
  2. /// 加载状态视图组件
  3. class LoadingView extends StatelessWidget {
  4. final String? message;
  5. final Color? color;
  6. final double? size;
  7. const LoadingView({
  8. super.key,
  9. this.message,
  10. this.color,
  11. this.size,
  12. });
  13. @override
  14. Widget build(BuildContext context) {
  15. return Center(
  16. child: Column(
  17. mainAxisAlignment: MainAxisAlignment.center,
  18. children: [
  19. SizedBox(
  20. width: size ?? 40,
  21. height: size ?? 40,
  22. child: CircularProgressIndicator(
  23. strokeWidth: 3,
  24. valueColor: AlwaysStoppedAnimation<Color>(
  25. color ?? Theme.of(context).colorScheme.primary,
  26. ),
  27. ),
  28. ),
  29. if (message != null) ...[
  30. const SizedBox(height: 16),
  31. Text(
  32. message!,
  33. style: Theme.of(context).textTheme.bodyMedium?.copyWith(
  34. color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
  35. ),
  36. ),
  37. ],
  38. ],
  39. ),
  40. );
  41. }
  42. }
  43. /// 全屏加载遮罩
  44. class LoadingOverlay extends StatelessWidget {
  45. final bool isLoading;
  46. final Widget child;
  47. final String? message;
  48. final Color? backgroundColor;
  49. const LoadingOverlay({
  50. super.key,
  51. required this.isLoading,
  52. required this.child,
  53. this.message,
  54. this.backgroundColor,
  55. });
  56. @override
  57. Widget build(BuildContext context) {
  58. return Stack(
  59. children: [
  60. child,
  61. if (isLoading)
  62. Container(
  63. color: backgroundColor ?? Colors.black.withOpacity(0.3),
  64. child: LoadingView(message: message),
  65. ),
  66. ],
  67. );
  68. }
  69. }