Skip to content

Commit e39a6e6

Browse files
committed
Making the WindowMetadata public and only refresing the relevant fields when settings change
1 parent 40ad0d6 commit e39a6e6

File tree

2 files changed

+64
-54
lines changed

2 files changed

+64
-54
lines changed

examples/multi_window_ref_app/lib/app/window_settings_dialog.dart

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ Future<void> windowSettingsDialog(
77
barrierDismissible: true,
88
context: context,
99
builder: (BuildContext ctx) {
10-
return ListenableBuilder(
11-
listenable: settings,
12-
builder: (BuildContext ctx, Widget? _) {
13-
return SimpleDialog(
14-
contentPadding: const EdgeInsets.all(4),
15-
titlePadding: const EdgeInsets.fromLTRB(24, 10, 24, 0),
16-
title: const Center(
17-
child: Text('Window Settings'),
18-
),
10+
return SimpleDialog(
11+
contentPadding: const EdgeInsets.all(4),
12+
titlePadding: const EdgeInsets.fromLTRB(24, 10, 24, 0),
13+
title: const Center(
14+
child: Text('Window Settings'),
15+
),
16+
children: [
17+
SizedBox(
18+
width: 600,
19+
child: Column(
20+
mainAxisSize: MainAxisSize.min,
1921
children: [
20-
SizedBox(
21-
width: 600,
22-
child: Column(
23-
mainAxisSize: MainAxisSize.min,
24-
children: [
25-
Row(
26-
children: [
27-
Expanded(
28-
child: ListTile(
29-
title: const Text('Regular'),
30-
subtitle: Row(
22+
Row(
23+
children: [
24+
Expanded(
25+
child: ListTile(
26+
title: const Text('Regular'),
27+
subtitle: ListenableBuilder(
28+
listenable: settings,
29+
builder: (BuildContext ctx, Widget? _) {
30+
return Row(
3131
children: [
3232
Expanded(
3333
child: TextFormField(
@@ -60,31 +60,31 @@ Future<void> windowSettingsDialog(
6060
),
6161
),
6262
],
63-
),
64-
),
65-
),
66-
const SizedBox(
67-
width: 10,
68-
),
69-
],
63+
);
64+
}),
7065
),
71-
],
72-
),
73-
),
74-
Padding(
75-
padding: const EdgeInsets.symmetric(horizontal: 16),
76-
child: TextButton(
77-
onPressed: () {
78-
Navigator.of(context, rootNavigator: true).pop();
79-
},
80-
child: const Text('Apply'),
81-
),
82-
),
83-
const SizedBox(
84-
height: 2,
66+
),
67+
const SizedBox(
68+
width: 10,
69+
),
70+
],
8571
),
8672
],
87-
);
88-
});
73+
),
74+
),
75+
Padding(
76+
padding: const EdgeInsets.symmetric(horizontal: 16),
77+
child: TextButton(
78+
onPressed: () {
79+
Navigator.of(context, rootNavigator: true).pop();
80+
},
81+
child: const Text('Apply'),
82+
),
83+
),
84+
const SizedBox(
85+
height: 2,
86+
),
87+
],
88+
);
8989
});
9090
}

packages/flutter/lib/src/widgets/window.dart

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ class RegularWindow extends StatefulWidget {
107107

108108
class _RegularWindowState extends State<RegularWindow> {
109109
_WindowListener? _listener;
110-
Future<_RegularWindowMetadata>? _future;
110+
Future<RegularWindowMetadata>? _future;
111111
_WindowingAppState? _app;
112112

113113
@override
114114
void initState() {
115115
super.initState();
116116
_future = createRegular(size: widget._preferredSize);
117-
_future!.then((_RegularWindowMetadata metadata) async {
117+
_future!.then((RegularWindowMetadata metadata) async {
118118
if (widget.controller != null) {
119119
widget.controller!.view = metadata.view;
120120
widget.controller!.parentViewId = metadata.parentViewId;
@@ -160,11 +160,11 @@ class _RegularWindowState extends State<RegularWindow> {
160160

161161
@override
162162
Widget build(BuildContext context) {
163-
return FutureBuilder<_RegularWindowMetadata>(
163+
return FutureBuilder<RegularWindowMetadata>(
164164
key: widget.key,
165165
future: _future,
166166
builder: (BuildContext context,
167-
AsyncSnapshot<_RegularWindowMetadata> metadata) {
167+
AsyncSnapshot<RegularWindowMetadata> metadata) {
168168
if (!metadata.hasData) {
169169
return const ViewCollection(views: <Widget>[]);
170170
}
@@ -196,17 +196,27 @@ class WindowContext extends InheritedWidget {
196196
}
197197
}
198198

199-
class _WindowMetadata {
200-
_WindowMetadata({required this.view, required this.size, this.parentViewId});
199+
/// Base class for window creation metadata.
200+
abstract class WindowMetadata {
201+
/// Creates generic window metadata.
202+
WindowMetadata({required this.view, required this.size, this.parentViewId});
201203

204+
/// The view associated with the window.
202205
final FlutterView view;
206+
207+
/// The size of the created window.
203208
final Size size;
209+
210+
/// The parent view of the window, if any.
204211
final int? parentViewId;
205212
}
206213

207-
class _RegularWindowMetadata extends _WindowMetadata {
208-
_RegularWindowMetadata(
209-
{required super.view, required super.size, super.parentViewId});
214+
/// Data object returned by [createRegular].
215+
class RegularWindowMetadata extends WindowMetadata {
216+
/// Creates metadata for a regular window. This should only be initialized
217+
/// by [createRegular].
218+
RegularWindowMetadata(
219+
{required super.view, required super.size});
210220
}
211221

212222
class _WindowCreationResult {
@@ -227,14 +237,14 @@ class _WindowCreationResult {
227237
/// widget instead of this method.
228238
///
229239
/// [size] the size of the new [Window] in pixels
230-
Future<_RegularWindowMetadata> createRegular({required Size size}) async {
240+
Future<RegularWindowMetadata> createRegular({required Size size}) async {
231241
final _WindowCreationResult metadata =
232242
await _createWindow(viewBuilder: (MethodChannel channel) async {
233243
return await channel.invokeMethod('createWindow', <String, dynamic>{
234244
'size': <int>[size.width.toInt(), size.height.toInt()],
235245
}) as Map<Object?, Object?>;
236246
});
237-
return _RegularWindowMetadata(view: metadata.flView, size: metadata.size);
247+
return RegularWindowMetadata(view: metadata.flView, size: metadata.size);
238248
}
239249

240250
Future<_WindowCreationResult> _createWindow(

0 commit comments

Comments
 (0)