mirror of
https://github.com/MeowLynxSea/vissh.git
synced 2025-07-09 19:44:34 +00:00
修复了最小化窗口时异常重载的问题
This commit is contained in:
parent
4fade2c4e8
commit
98ca5c46d0
@ -268,6 +268,9 @@ class _WindowManagerState extends State<WindowManager> {
|
||||
);
|
||||
}
|
||||
|
||||
final topMostIndex = _windows.lastIndexWhere((w) => !w.isMinimized);
|
||||
final activeWindowId = topMostIndex != -1 ? _windows[topMostIndex].id : null;
|
||||
|
||||
final sortedWindowsForTaskbar = List<WindowData>.from(_windows);
|
||||
sortedWindowsForTaskbar.sort((a, b) {
|
||||
final aId = int.tryParse(a.id.split('_').last) ?? 0;
|
||||
@ -275,9 +278,6 @@ class _WindowManagerState extends State<WindowManager> {
|
||||
return aId.compareTo(bId);
|
||||
});
|
||||
|
||||
final topMostIndex = _windows.lastIndexWhere((w) => !w.isMinimized);
|
||||
final activeWindowId = topMostIndex != -1 ? _windows[topMostIndex].id : null;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.blueGrey[900],
|
||||
body: Container(
|
||||
@ -291,26 +291,33 @@ class _WindowManagerState extends State<WindowManager> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Stack(
|
||||
children: _windows.where((w) => !w.isMinimized).map((data) {
|
||||
final bool isActive = data.id == activeWindowId;
|
||||
return DraggableWindow(
|
||||
key: ValueKey(data.id),
|
||||
id: data.id,
|
||||
initialPosition: data.position,
|
||||
initialSize: data.size,
|
||||
title: data.title,
|
||||
icon: data.icon,
|
||||
isActive: isActive,
|
||||
isMaximized: data.isMaximized,
|
||||
onBringToFront: _bringToFront,
|
||||
onMinimize: _minimizeWindow,
|
||||
onClose: _removeWindow,
|
||||
onMove: _updateWindowPosition,
|
||||
onResize: _updateWindowSize,
|
||||
onMaximizeChanged: _updateWindowMaximizeState,
|
||||
child: data.child,
|
||||
);
|
||||
}).toList(),
|
||||
// 使用 collection for 循环来构建子组件列表,以获得更好的性能和稳定性。
|
||||
children: [
|
||||
for (final data in _windows)
|
||||
Offstage(
|
||||
// 使用 Offstage 来隐藏最小化的窗口。
|
||||
// Offstage 会完整地保留子组件的状态 (state),即使它不可见。
|
||||
offstage: data.isMinimized,
|
||||
child: DraggableWindow(
|
||||
key: data.key,
|
||||
id: data.id,
|
||||
initialPosition: data.position,
|
||||
initialSize: data.size,
|
||||
title: data.title,
|
||||
icon: data.icon,
|
||||
isActive: data.id == activeWindowId,
|
||||
isMaximized: data.isMaximized,
|
||||
isMinimized: data.isMinimized,
|
||||
onBringToFront: _bringToFront,
|
||||
onMinimize: _minimizeWindow,
|
||||
onClose: _removeWindow,
|
||||
onMove: _updateWindowPosition,
|
||||
onResize: _updateWindowSize,
|
||||
onMaximizeChanged: _updateWindowMaximizeState,
|
||||
child: data.child,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Taskbar(
|
||||
|
@ -10,6 +10,8 @@ class WindowData {
|
||||
bool isMinimized;
|
||||
bool isMaximized;
|
||||
|
||||
final GlobalKey key = GlobalKey();
|
||||
|
||||
WindowData({
|
||||
required this.id,
|
||||
required this.title,
|
||||
|
@ -15,6 +15,7 @@ class DraggableWindow extends StatefulWidget {
|
||||
final IconData icon;
|
||||
final bool isActive;
|
||||
final bool isMaximized;
|
||||
final bool isMinimized;
|
||||
final Function(String, bool) onMaximizeChanged;
|
||||
final Function(String) onBringToFront;
|
||||
final Function(String) onClose;
|
||||
@ -34,6 +35,7 @@ class DraggableWindow extends StatefulWidget {
|
||||
required this.onBringToFront,
|
||||
required this.onClose,
|
||||
required this.onMinimize,
|
||||
required this.isMinimized,
|
||||
required this.onMove,
|
||||
required this.onResize,
|
||||
required this.isMaximized,
|
||||
@ -110,6 +112,15 @@ class _DraggableWindowState extends State<DraggableWindow> {
|
||||
@override
|
||||
void didUpdateWidget(covariant DraggableWindow oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
|
||||
if (oldWidget.isMinimized && !widget.isMinimized) {
|
||||
if (_isClosing) {
|
||||
setState(() {
|
||||
_isClosing = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (widget.initialPosition != oldWidget.initialPosition) {
|
||||
_top = widget.initialPosition.dy;
|
||||
_left = widget.initialPosition.dx;
|
||||
|
Loading…
Reference in New Issue
Block a user