refactored overlay loading indicator code
This commit is contained in:
47
lib/services/overlay_service.dart
Normal file
47
lib/services/overlay_service.dart
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user