修复了最小化窗口时异常重载的问题

This commit is contained in:
梦凌汐 2025-07-09 19:36:26 +08:00
parent 4fade2c4e8
commit 98ca5c46d0
3 changed files with 43 additions and 23 deletions

View File

@ -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(

View File

@ -10,6 +10,8 @@ class WindowData {
bool isMinimized;
bool isMaximized;
final GlobalKey key = GlobalKey();
WindowData({
required this.id,
required this.title,

View File

@ -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;