refactored overlay loading indicator code

This commit is contained in:
2025-01-28 15:36:14 +01:00
parent 9c9992919d
commit 68b0d5834d
2 changed files with 121 additions and 79 deletions

View File

@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
import '../widgets/loading_notifier.dart';
mixin OverlayService {
OverlayEntry? _overlayEntry;
Future<void> showLoadingNotifier({
required BuildContext context,
required String message,
required VoidCallback onDismiss,
}) async {
if (_overlayEntry != null) return;
final overlayState = Overlay.of(context);
_overlayEntry = OverlayEntry(
builder: (context) => Positioned(
bottom: 85,
left: 0,
right: 0,
child: Center(
child: LoadingNotifier(
message: message,
onDismissed: () {
onDismiss();
removeLoadingNotifier();
},
),
),
),
);
overlayState.insert(_overlayEntry!);
// overlayState.setState(() {});
}
void removeLoadingNotifier() {
if (_overlayEntry != null) {
_overlayEntry?.remove();
_overlayEntry = null;
}
}
void dispose() {
removeLoadingNotifier();
}
}