mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-13 03:28:03 +00:00
refactor OverlayKeyState for OverlayDialogManager and ChatModel
This commit is contained in:
@@ -369,20 +369,25 @@ class Dialog<T> {
|
||||
}
|
||||
}
|
||||
|
||||
class OverlayKeyState {
|
||||
final _overlayKey = GlobalKey<OverlayState>();
|
||||
|
||||
/// use global overlay by default
|
||||
OverlayState? get state =>
|
||||
_overlayKey.currentState ?? globalKey.currentState?.overlay;
|
||||
|
||||
GlobalKey<OverlayState>? get key => _overlayKey;
|
||||
}
|
||||
|
||||
class OverlayDialogManager {
|
||||
OverlayState? _overlayState;
|
||||
final Map<String, Dialog> _dialogs = {};
|
||||
var _overlayKeyState = OverlayKeyState();
|
||||
int _tagCount = 0;
|
||||
|
||||
OverlayEntry? _mobileActionsOverlayEntry;
|
||||
|
||||
/// By default OverlayDialogManager use global overlay
|
||||
OverlayDialogManager() {
|
||||
_overlayState = globalKey.currentState?.overlay;
|
||||
}
|
||||
|
||||
void setOverlayState(OverlayState? overlayState) {
|
||||
_overlayState = overlayState;
|
||||
void setOverlayState(OverlayKeyState overlayKeyState) {
|
||||
_overlayKeyState = overlayKeyState;
|
||||
}
|
||||
|
||||
void dismissAll() {
|
||||
@@ -406,7 +411,7 @@ class OverlayDialogManager {
|
||||
bool useAnimation = true,
|
||||
bool forceGlobal = false}) {
|
||||
final overlayState =
|
||||
forceGlobal ? globalKey.currentState?.overlay : _overlayState;
|
||||
forceGlobal ? globalKey.currentState?.overlay : _overlayKeyState.state;
|
||||
|
||||
if (overlayState == null) {
|
||||
return Future.error(
|
||||
@@ -510,7 +515,8 @@ class OverlayDialogManager {
|
||||
|
||||
void showMobileActionsOverlay({FFI? ffi}) {
|
||||
if (_mobileActionsOverlayEntry != null) return;
|
||||
if (_overlayState == null) return;
|
||||
final overlayState = _overlayKeyState.state;
|
||||
if (overlayState == null) return;
|
||||
|
||||
// compute overlay position
|
||||
final screenW = MediaQuery.of(globalKey.currentContext!).size.width;
|
||||
@@ -536,7 +542,7 @@ class OverlayDialogManager {
|
||||
onHidePressed: () => hideMobileActionsOverlay(),
|
||||
);
|
||||
});
|
||||
_overlayState!.insert(overlay);
|
||||
overlayState.insert(overlay);
|
||||
_mobileActionsOverlayEntry = overlay;
|
||||
}
|
||||
|
||||
@@ -1701,4 +1707,4 @@ Future<void> updateSystemWindowTheme() async {
|
||||
: SystemWindowTheme.dark);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user