Files
floodwatch/lib/services/overlay_service.dart

48 lines
1018 B
Dart

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();
}
}