123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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<LoadingOverlayState>()!;
- }
- @override
- State<LoadingOverlay> createState() => LoadingOverlayState();
- }
- class LoadingOverlayState extends State<LoadingOverlay> {
- 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,
- ),
- ],
- );
- }
- }
|