import 'package:flutter/material.dart'; /// 加载状态视图组件 class LoadingView extends StatelessWidget { final String? message; final Color? color; final double? size; const LoadingView({ super.key, this.message, this.color, this.size, }); @override Widget build(BuildContext context) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox( width: size ?? 40, height: size ?? 40, child: CircularProgressIndicator( strokeWidth: 3, valueColor: AlwaysStoppedAnimation( color ?? Theme.of(context).colorScheme.primary, ), ), ), if (message != null) ...[ const SizedBox(height: 16), Text( message!, style: Theme.of(context).textTheme.bodyMedium?.copyWith( color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6), ), ), ], ], ), ); } } /// 全屏加载遮罩 class LoadingOverlay extends StatelessWidget { final bool isLoading; final Widget child; final String? message; final Color? backgroundColor; const LoadingOverlay({ super.key, required this.isLoading, required this.child, this.message, this.backgroundColor, }); @override Widget build(BuildContext context) { return Stack( children: [ child, if (isLoading) Container( color: backgroundColor ?? Colors.black.withOpacity(0.3), child: LoadingView(message: message), ), ], ); } }