Matthew Kosarek fe409cfca4
Implement dialog windows for the win32 platform (#176309)
## What's new?
- Implemented `DialogWindowControllerWin32` for win32 dialogs 🚀
- Refactored and updated the Win32 embedder to support dialogs
- Updated the `multiple_windows` example to demonstrate both modal and
modeless dialogs
- Added integration tests for the dialog windows
- Added tests for dialogs in the embedder

## How to test?
1. Run the `multiple_windows` example application with a local engine
built from this pull request
2. Click the `Modeless Dialog` creation button on the main window
3. Open a regular window and click the `Modal Dialog` creation button
4. Note the behavior of modal and modeless dialogs

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
2025-10-16 15:32:29 +00:00

100 lines
2.9 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: invalid_use_of_internal_member
// ignore_for_file: implementation_imports
import 'package:flutter/widgets.dart';
import 'package:flutter/src/widgets/_window.dart';
class KeyedWindow {
KeyedWindow({
this.parent,
this.isMainWindow = false,
required this.key,
required this.controller,
});
final BaseWindowController? parent;
final bool isMainWindow;
final UniqueKey key;
final BaseWindowController controller;
}
/// Provides access to the windows created by the application.
///
/// The window manager manages a flat list of all of the [BaseWindowController]s
/// that have been created by the application as well as which controller is
/// currently selected by the UI.
class WindowManager extends ChangeNotifier {
WindowManager({required List<KeyedWindow> initialWindows})
: _windows = initialWindows;
final List<KeyedWindow> _windows;
List<KeyedWindow> get windows => _windows;
void add(KeyedWindow window) {
_windows.add(window);
notifyListeners();
}
void remove(UniqueKey key) {
_windows.removeWhere((KeyedWindow window) => window.key == key);
notifyListeners();
}
}
/// Provides access to the [WindowManager] from the widget tree.
class WindowManagerAccessor extends InheritedNotifier<WindowManager> {
const WindowManagerAccessor({
super.key,
required super.child,
required WindowManager windowManager,
}) : super(notifier: windowManager);
static WindowManager of(BuildContext context) {
final WindowManagerAccessor? result = context
.dependOnInheritedWidgetOfExactType<WindowManagerAccessor>();
assert(result != null, 'No WindowManager found in context');
return result!.notifier!;
}
}
/// Settings that control the behavior of newly created windows.
class WindowSettings {
WindowSettings({
this.regularSize = const Size(400, 300),
this.dialogSize = const Size(200, 200),
});
/// The initial size for newly created regular windows.
Size regularSize;
/// The initial size of the dialog window.
Size dialogSize;
}
/// Provides access to the [WindowSettings] from the widget tree.
class WindowSettingsAccessor extends InheritedWidget {
const WindowSettingsAccessor({
super.key,
required super.child,
required this.windowSettings,
});
final WindowSettings windowSettings;
static WindowSettings of(BuildContext context) {
final WindowSettingsAccessor? result = context
.dependOnInheritedWidgetOfExactType<WindowSettingsAccessor>();
assert(result != null, 'No WindowSettings found in context');
return result!.windowSettings;
}
@override
bool updateShouldNotify(WindowSettingsAccessor oldWidget) {
return windowSettings != oldWidget.windowSettings;
}
}