import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; class LoadingOverlay extends StatefulWidget { const LoadingOverlay({ Key? key, required this.child, this.delay = const Duration(milliseconds: 500), }) : super(key: key); final Widget child; final Duration delay; static LoadingOverlayState of(BuildContext context) { return context.findAncestorStateOfType()!; } @override State createState() => LoadingOverlayState(); } class LoadingOverlayState extends State { bool _isLoading = false; void show() { setState(() { _isLoading = true; }); } void hide() { setState(() { _isLoading = false; }); } @override Widget build(BuildContext context) { return Stack( children: [ widget.child, if (_isLoading) BackdropFilter( filter: ImageFilter.blur(sigmaX: 4.0, sigmaY: 4.0), child: const Opacity( opacity: 0.2, child: ModalBarrier(dismissible: false, color: Colors.black), ), ), if (_isLoading) const SpinKitDualRing( color: Colors.red, size: 50.0, ), ], ); } }