import 'package:flutter/material.dart'; /// 全屏/局部 loading 遮罩。 /// /// 用法: /// ```dart /// LoadingOverlay( /// loading: _isLoading, /// child: MyWidget(), /// ) /// ``` class LoadingOverlay extends StatelessWidget { const LoadingOverlay({ super.key, required this.child, this.loading = false, this.label, }); final Widget child; final bool loading; final String? label; @override Widget build(BuildContext context) { return Stack( children: [ child, if (loading) Positioned.fill( child: ColoredBox( color: Colors.black26, child: Center( child: Card( child: Padding( padding: const EdgeInsets.symmetric( horizontal: 32, vertical: 24), child: Column( mainAxisSize: MainAxisSize.min, children: [ const CircularProgressIndicator(), if (label != null) ...[ const SizedBox(height: 12), Text(label!, style: Theme.of(context).textTheme.bodySmall), ], ], ), ), ), ), ), ), ], ); } }