-
Notifications
You must be signed in to change notification settings - Fork 30.6k
Windowing implementation of showDialog that uses a native desktop window to display the content
#181861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mattkae
merged 56 commits into
flutter:master
from
canonical:feature/material_dialogs_multi_window
Mar 5, 2026
Merged
Windowing implementation of showDialog that uses a native desktop window to display the content
#181861
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
6b60503
Add the useWindowing flag to the MaterialApp
mattkae 569237b
Provide the windowing configuraton to MaterialApp descendents internally
mattkae 65606bc
Getting somewhere
mattkae a3b5ae4
Cleaning up the implementation
mattkae 42c4f88
Reset
mattkae 551b874
Fix error
mattkae c3ab6d8
Falling back to the non-windowed implementation when dialogs are not …
mattkae 030576a
Implement proper documentation
mattkae bb6c715
Fullscreen example
mattkae a577cee
Adding tests
mattkae 133dbaa
Add checksum
mattkae 8c2e1ca
Add checksum again
mattkae c3fb870
Remove useWindowing flag from MaterialApp in favor of using the windo…
mattkae d914b44
Marking certain APIs as experimental, throwing where necessary
mattkae 21a0e53
Genericizing the WindowRegistry
mattkae 731445f
PR feedback
mattkae dd3dee8
Fix missing doc directive
mattkae dbccf37
Significantly improving the WindowManager API
mattkae 35a1d33
PR feedback
mattkae 4cf5571
Fixing some formatting issues
mattkae 44e490d
Fix import issues
mattkae 308c8f0
Conditionally providing the WindowManager
mattkae 3066811
More linux analyze shenanigans
mattkae 2584c84
Skipping api_multiwindow build explicitly
mattkae ff3aec7
Making WindowRegistry.maybeOf NOT throw when windowing is unavailable…
mattkae 44109dd
Minor pull request feedback
mattkae 4a40467
Merge branch 'master' into feature/material_dialogs_multi_window
mattkae 9302ca5
Moving usafe of windowing internals to the widgets API
mattkae c9dc047
Revert "Moving usafe of windowing internals to the widgets API"
mattkae 513fba5
Re-add moving to the WidgetApp and fixing the Hero issue
mattkae 07b4992
showRawDialog
justinmc e3bbe32
Cleanup
justinmc fee18f5
Material dialogs multi window widgets (#66)
mattkae 3ac0c26
Reset app.dart
mattkae 184301a
Re-add newline
mattkae 03c25de
feedback
mattkae c5d95a5
Breaking out the WindowManager exampleinto its own file
mattkae 937f67d
More feedback + fixing linux analyze
mattkae 785f0cc
Remove api_multiwindow
mattkae a850d58
Pull request feedback
mattkae 684ea47
Add missing imports
mattkae dddd1bf
Simplifying the showRawDialog method
mattkae 280e795
Remove unused import
mattkae 8e3ebd8
Merge branch 'master' into feature/material_dialogs_multi_window
mattkae ee80c0d
PR feedback
mattkae 76159c2
Fixes
mattkae 47667fe
Linux analyze
mattkae 8054c49
Fixing context issues
mattkae b8cb64a
Whoops, forgot this
mattkae 6b652eb
Fix for context
mattkae c823f80
PR feedback
mattkae eb2e05b
Making less of a diff
mattkae d38fa48
Fix dart doc
mattkae 6eb1053
Rename RouteBuilder to DialogRouteBuilder to avoid collisions
mattkae 39d60ec
Merge branch 'master' into feature/material_dialogs_multi_window
mattkae 6538a43
Rename DialogRouteBuilder to RawDialogRouteBuilder
mattkae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // 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. | ||
|
|
||
| // TODO(mattkae): remove invalid_use_of_internal_member ignore comment when this API is stable. | ||
| // See: https://github.com/flutter/flutter/issues/177586 | ||
| // 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'; | ||
|
|
||
| void main() { | ||
| try { | ||
| WidgetsFlutterBinding.ensureInitialized(); | ||
| final RegularWindowController controller = RegularWindowController( | ||
| preferredSize: const Size(800, 600), | ||
| ); | ||
| runWidget( | ||
| WindowManager( | ||
| child: RegularWindow(controller: controller, child: const MainWindow()), | ||
| ), | ||
| ); | ||
| } on UnsupportedError catch (e) { | ||
| // TODO(mattkae): Remove this catch block when windowing is supported in tests. | ||
| // For now, we need to catch the error so that the API smoke tests pass. | ||
| runApp( | ||
| WidgetsApp( | ||
| color: const Color(0xFFFFFFFF), | ||
| builder: (BuildContext context, Widget? child) { | ||
| return Center( | ||
| child: Text( | ||
| e.message ?? 'Unsupported', | ||
| textDirection: TextDirection.ltr, | ||
| ), | ||
| ); | ||
| }, | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class MainWindow extends StatefulWidget { | ||
| const MainWindow({super.key}); | ||
|
|
||
| @override | ||
| State<StatefulWidget> createState() => MainWindowState(); | ||
| } | ||
|
|
||
| class MainWindowState extends State<MainWindow> { | ||
| WindowEntry? entry; | ||
|
|
||
| void _openDialog(BuildContext context) { | ||
| final WindowRegistry? registry = WindowRegistry.maybeOf(context); | ||
| assert(registry != null); | ||
| entry = WindowEntry( | ||
| controller: DialogWindowController( | ||
| parent: WindowScope.of(context), | ||
| preferredSize: const Size(400, 300), | ||
| delegate: _DialogWindowControllerDelegate( | ||
| mainWindow: this, | ||
| registry: registry!, | ||
| ), | ||
| ), | ||
| builder: (BuildContext context) { | ||
| return const SizedBox.shrink(); | ||
| }, | ||
| ); | ||
| registry.register(entry!); | ||
| } | ||
|
|
||
| void closeDialog(WindowRegistry registry) { | ||
| if (entry != null) { | ||
| registry.unregister(entry!); | ||
| entry = null; | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return WidgetsApp( | ||
| color: const Color(0xFFFFFFFF), | ||
| builder: (BuildContext context, Widget? child) { | ||
| return Center( | ||
| child: GestureDetector( | ||
| onTap: () => _openDialog(context), | ||
| child: const Text( | ||
| 'Open a dialog', | ||
| textDirection: TextDirection.ltr, | ||
| ), | ||
| ), | ||
| ); | ||
| }, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class _DialogWindowControllerDelegate extends DialogWindowControllerDelegate { | ||
| _DialogWindowControllerDelegate({ | ||
| required this.mainWindow, | ||
| required this.registry, | ||
| }); | ||
|
|
||
| final MainWindowState mainWindow; | ||
| final WindowRegistry registry; | ||
|
|
||
| @override | ||
| void onWindowDestroyed() { | ||
| super.onWindowDestroyed(); | ||
| mainWindow.closeDialog(registry); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
examples/api/test/widgets/windows/window_manager.0_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // 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. | ||
|
|
||
| import 'package:flutter_api_samples/widgets/windows/window_manager.0.dart' | ||
| as example; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| void main() { | ||
| testWidgets('Calling window_manager main returns normally', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| expect(() => example.main(), returnsNormally); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to pump the example and expect that "Unsupported" is shown?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left it as "returns normally" so that when we "turn on" multi-window, it will just work