Skip to content

Commit df92dd1

Browse files
authored
refactor: remove references to WindowingApp from the window.dart API (#21)
* refactor: remove references to WindowingApp from the window.dart API * bugfix: notify listeners when values change on a window controller
1 parent ba564ea commit df92dd1

File tree

3 files changed

+10
-51
lines changed

3 files changed

+10
-51
lines changed

examples/multi_window_ref_app/lib/main.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ void main() {
77
sizeConstraints: const BoxConstraints(minWidth: 640, minHeight: 480),
88
title: "Multi-Window Reference Application",
99
);
10-
runWidget(WindowingApp(children: <Widget>[
11-
RegularWindow(
12-
controller: controller,
13-
child: MaterialApp(home: MainWindow(mainController: controller)))
14-
]));
10+
runWidget(RegularWindow(
11+
controller: controller,
12+
child: MaterialApp(home: MainWindow(mainController: controller))));
1513
}

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

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,21 @@ abstract class WindowController with ChangeNotifier {
4040
_view = metadata.view;
4141
_state = metadata.state;
4242
_size = metadata.size;
43+
notifyListeners();
4344

4445
SchedulerBinding.instance.addPostFrameCallback((_) async {
4546
_listener = _WindowListener(
4647
viewId: metadata.view.viewId,
4748
onChanged: (_WindowChangeProperties properties) {
4849
if (properties.size != null) {
4950
_size = properties.size!;
51+
notifyListeners();
5052
}
5153
},
5254
onDestroyed: () {
5355
_view = null;
5456
_isPendingDestroy = false;
57+
notifyListeners();
5558
onDestroyed?.call();
5659
},
5760
);
@@ -381,39 +384,3 @@ class _WindowingAppGlobalData {
381384
_listeners.add(listener);
382385
}
383386
}
384-
385-
/// Declares that an application will create multiple windows.
386-
class WindowingApp extends StatefulWidget {
387-
/// Creates a new windowing app with the provided child windows.
388-
const WindowingApp({super.key, required this.children});
389-
390-
/// A list of initial windows to render. These windows will be placed inside
391-
/// of a [ViewCollection].
392-
final List<Widget> children;
393-
394-
@override
395-
State<WindowingApp> createState() => _WindowingAppState();
396-
}
397-
398-
class _WindowingAppState extends State<WindowingApp> {
399-
@override
400-
Widget build(BuildContext context) {
401-
return _WindowingAppContext(windowingApp: this, child: ViewCollection(views: widget.children));
402-
}
403-
}
404-
405-
class _WindowingAppContext extends InheritedWidget {
406-
const _WindowingAppContext({super.key, required super.child, required this.windowingApp});
407-
408-
final _WindowingAppState windowingApp;
409-
410-
/// Returns the [MultiWindowAppContext] if any
411-
static _WindowingAppContext? of(BuildContext context) {
412-
return context.dependOnInheritedWidgetOfExactType<_WindowingAppContext>();
413-
}
414-
415-
@override
416-
bool updateShouldNotify(_WindowingAppContext oldWidget) {
417-
return windowingApp != oldWidget.windowingApp;
418-
}
419-
}

packages/flutter/test/widgets/window_test.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ void main() {
4646
wrapWithView: false,
4747
Builder(
4848
builder: (BuildContext context) {
49-
return WindowingApp(
50-
children: <Widget>[RegularWindow(controller: controller, child: Container())],
51-
);
49+
return RegularWindow(controller: controller, child: Container());
5250
},
5351
),
5452
);
@@ -57,7 +55,7 @@ void main() {
5755

5856
expect(controller.type, WindowArchetype.regular);
5957
expect(controller.size, windowSize);
60-
expect(controller.view!.viewId, tester.view.viewId);
58+
expect(controller.view.viewId, tester.view.viewId);
6159
});
6260

6361
testWidgets('RegularWindow.onError is called when creation throws an error', (
@@ -105,9 +103,7 @@ void main() {
105103
wrapWithView: false,
106104
Builder(
107105
builder: (BuildContext context) {
108-
return WindowingApp(
109-
children: <Widget>[RegularWindow(controller: controller, child: Container())],
110-
);
106+
return RegularWindow(controller: controller, child: Container());
111107
},
112108
),
113109
);
@@ -135,9 +131,7 @@ void main() {
135131
wrapWithView: false,
136132
Builder(
137133
builder: (BuildContext context) {
138-
return WindowingApp(
139-
children: <Widget>[RegularWindow(controller: controller, child: Container())],
140-
);
134+
return RegularWindow(controller: controller, child: Container());
141135
},
142136
),
143137
);

0 commit comments

Comments
 (0)