mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
## What's new? - Implemented `_TestTooltipWindowController` in the `TestWindowingOwner` - Fixed how child windows of the main window are rendered in the application - Introduced `WindowManager.getChildrenOf` to simplify filtering and rendering of the children of a parent window - Added a test for the tooltip window - Added a test for modal dialogs of the main window ## 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.
101 lines
2.7 KiB
Dart
101 lines
2.7 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 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'app/models.dart';
|
|
import 'app/window_content.dart';
|
|
import 'app/main_window.dart';
|
|
import 'package:flutter/src/widgets/_window.dart';
|
|
|
|
class MainControllerWindowDelegate with RegularWindowControllerDelegate {
|
|
@override
|
|
void onWindowDestroyed() {
|
|
super.onWindowDestroyed();
|
|
exit(0);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
runWidget(MultiWindowApp());
|
|
}
|
|
|
|
class MultiWindowApp extends StatefulWidget {
|
|
const MultiWindowApp({super.key});
|
|
|
|
@override
|
|
State<MultiWindowApp> createState() => _MultiWindowAppState();
|
|
}
|
|
|
|
class _MultiWindowAppState extends State<MultiWindowApp> {
|
|
final RegularWindowController controller = RegularWindowController(
|
|
preferredSize: const Size(800, 600),
|
|
title: 'Multi-Window Reference Application',
|
|
delegate: MainControllerWindowDelegate(),
|
|
);
|
|
final WindowSettings settings = WindowSettings();
|
|
late final WindowManager windowManager;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
windowManager = WindowManager(
|
|
initialWindows: <KeyedWindow>[
|
|
KeyedWindow(
|
|
isMainWindow: true,
|
|
key: UniqueKey(),
|
|
controller: controller,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Widget mainWindowWidget = RegularWindow(
|
|
controller: controller,
|
|
child: MaterialApp(home: MainWindow(controller: controller)),
|
|
);
|
|
return WindowManagerAccessor(
|
|
windowManager: windowManager,
|
|
child: WindowSettingsAccessor(
|
|
windowSettings: settings,
|
|
child: ListenableBuilder(
|
|
listenable: windowManager,
|
|
builder: (BuildContext context, Widget? child) {
|
|
final List<Widget> childViews = <Widget>[mainWindowWidget];
|
|
for (final KeyedWindow window in windowManager.getWindows(
|
|
parent: null,
|
|
)) {
|
|
if (!window.isMainWindow) {
|
|
childViews.add(
|
|
WindowContent(
|
|
controller: window.controller,
|
|
windowKey: window.key,
|
|
onDestroyed: () => windowManager.remove(window.key),
|
|
onError: () => windowManager.remove(window.key),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
return ViewCollection(views: childViews);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|