Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 37 additions & 39 deletions examples/multi_window_ref_app/lib/app/main_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import 'regular_window_edit_dialog.dart';

class MainWindow extends StatefulWidget {
MainWindow({super.key, required WindowController mainController}) {
_windowManagerModel.add(
KeyedWindowController(isMainWindow: true, key: UniqueKey(), controller: mainController));
_windowManagerModel.add(KeyedWindowController(
isMainWindow: true, key: UniqueKey(), controller: mainController));
}

final WindowManagerModel _windowManagerModel = WindowManagerModel();
Expand All @@ -38,7 +38,8 @@ class _MainWindowState extends State<MainWindow> {
flex: 60,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: _ActiveWindowsTable(windowManagerModel: widget._windowManagerModel),
child: _ActiveWindowsTable(
windowManagerModel: widget._windowManagerModel),
),
),
Expanded(
Expand Down Expand Up @@ -66,15 +67,18 @@ class _MainWindowState extends State<MainWindow> {
listenable: widget._windowManagerModel,
builder: (BuildContext context, Widget? _) {
final List<Widget> childViews = <Widget>[];
for (final KeyedWindowController controller in widget._windowManagerModel.windows) {
for (final KeyedWindowController controller
in widget._windowManagerModel.windows) {
if (controller.parent == null && !controller.isMainWindow) {
childViews.add(WindowControllerRender(
controller: controller.controller,
key: controller.key,
windowSettings: widget._settings,
windowManagerModel: widget._windowManagerModel,
onDestroyed: () => widget._windowManagerModel.remove(controller.key),
onError: () => widget._windowManagerModel.remove(controller.key),
onDestroyed: () =>
widget._windowManagerModel.remove(controller.key),
onError: () =>
widget._windowManagerModel.remove(controller.key),
));
}
}
Expand Down Expand Up @@ -130,7 +134,8 @@ class _ActiveWindowsTable extends StatelessWidget {
),
numeric: true),
],
rows: (windowManagerModel.windows).map<DataRow>((KeyedWindowController controller) {
rows: (windowManagerModel.windows)
.map<DataRow>((KeyedWindowController controller) {
return DataRow(
key: controller.key,
color: WidgetStateColor.resolveWith((states) {
Expand All @@ -142,49 +147,30 @@ class _ActiveWindowsTable extends StatelessWidget {
selected: controller.controller == windowManagerModel.selected,
onSelectChanged: (selected) {
if (selected != null) {
windowManagerModel
.select(selected ? controller.controller.rootView.viewId : null);
windowManagerModel.select(selected
? controller.controller.rootView.viewId
: null);
}
},
cells: [
DataCell(Text('${controller.controller.rootView.viewId}')),
DataCell(
ListenableBuilder(
listenable: controller.controller,
builder: (BuildContext context, Widget? _) => Text(controller
.controller.type
.toString()
.replaceFirst('WindowArchetype.', ''))),
builder: (BuildContext context, Widget? _) => Text(
controller.controller.type
.toString()
.replaceFirst('WindowArchetype.', ''))),
),
DataCell(
ListenableBuilder(
listenable: controller.controller,
builder: (BuildContext context, Widget? _) => Row(children: [
builder: (BuildContext context, Widget? _) =>
Row(children: [
IconButton(
icon: const Icon(Icons.edit_outlined),
onPressed: () {
if (controller.controller.type == WindowArchetype.regular) {
showRegularWindowEditDialog(
context,
initialWidth: controller.controller.contentSize.width,
initialHeight: controller.controller.contentSize.height,
initialTitle: "",
onSave: (double? width, double? height, String? title) {
final regularController =
controller.controller as RegularWindowController;
if (width != null && height != null) {
regularController.updateContentSize(
WindowSizing(preferredSize: Size(width, height)),
);
}
if (title != null) {
regularController.setTitle(title);
}
},
);
}
},
),
icon: const Icon(Icons.edit_outlined),
onPressed: () => _showWindowEditDialog(
controller, context)),
IconButton(
icon: const Icon(Icons.delete_outlined),
onPressed: () async {
Expand All @@ -199,6 +185,17 @@ class _ActiveWindowsTable extends StatelessWidget {
);
});
}

void _showWindowEditDialog(
KeyedWindowController controller, BuildContext context) {
if (controller.controller.type != WindowArchetype.regular) {
return;
}

showRegularWindowEditDialog(
context: context,
controller: controller.controller as RegularWindowController);
}
}

class _WindowCreatorCard extends StatelessWidget {
Expand Down Expand Up @@ -243,7 +240,8 @@ class _WindowCreatorCard extends StatelessWidget {
onDestroyed: () => windowManagerModel.remove(key),
),
title: "Regular",
contentSize: WindowSizing(preferredSize: windowSettings.regularSize),
contentSize: WindowSizing(
preferredSize: windowSettings.regularSize),
)));
},
child: const Text('Regular'),
Expand Down
226 changes: 171 additions & 55 deletions examples/multi_window_ref_app/lib/app/regular_window_edit_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,180 @@
import 'package:flutter/material.dart';

void showRegularWindowEditDialog(
BuildContext context, {
double? initialWidth,
double? initialHeight,
String? initialTitle,
Function(double?, double?, String?)? onSave,
}) {
final TextEditingController widthController =
TextEditingController(text: initialWidth?.toString() ?? '');
final TextEditingController heightController =
TextEditingController(text: initialHeight?.toString() ?? '');
final TextEditingController titleController = TextEditingController(text: initialTitle ?? '');

{required BuildContext context,
required RegularWindowController controller}) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("Edit Window Properties"),
content: StatefulBuilder(
builder: (context, setState) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: widthController,
keyboardType: TextInputType.number,
decoration: InputDecoration(labelText: "Width"),
),
TextField(
controller: heightController,
keyboardType: TextInputType.number,
decoration: InputDecoration(labelText: "Height"),
),
TextField(
controller: titleController,
decoration: InputDecoration(labelText: "Title"),
),
],
);
},
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text("Cancel"),
context: context,
builder: (context) => _RegularWindowEditDialog(
controller: controller, onClose: () => Navigator.pop(context)));
}

class _RegularWindowEditDialog extends StatefulWidget {
const _RegularWindowEditDialog(
{required this.controller, required this.onClose});

final RegularWindowController controller;
final VoidCallback onClose;

@override
State<StatefulWidget> createState() => _RegularWindowEditDialogState();
}

class _RegularWindowEditDialogState extends State<_RegularWindowEditDialog> {
late Size initialSize;
late String initialTitle;
late bool initialFullscreen;
late bool initialMaximized;
late bool initialMinimized;

late final TextEditingController widthController;
late final TextEditingController heightController;
late final TextEditingController titleController;

bool? nextIsFullscreen;
bool? nextIsMaximized;
bool? nextIsMinized;

@override
void initState() {
super.initState();
initialSize = widget.controller.contentSize;
initialTitle = ""; // TODO: Get the title
initialFullscreen = widget.controller.isFullscreen();
initialMaximized = widget.controller.isMaximized();
initialMinimized = widget.controller.isMinimized();

widthController = TextEditingController(text: initialSize.width.toString());
heightController =
TextEditingController(text: initialSize.height.toString());
titleController = TextEditingController(text: initialTitle);

widget.controller.addListener(_onNotification);
}

void _onNotification() {
// We listen on the state of the controller. If a value that the user
// can edit changes from what it was initially set to, we invalidate
// their current change and store the new "initial" value.
if (widget.controller.contentSize != initialSize) {
initialSize = widget.controller.contentSize;
widthController.text = widget.controller.contentSize.width.toString();
heightController.text = widget.controller.contentSize.height.toString();
}
if (widget.controller.isFullscreen() != initialFullscreen) {
setState(() {
initialFullscreen = widget.controller.isFullscreen();
nextIsFullscreen = null;
});
}
if (widget.controller.isMaximized() != initialMaximized) {
setState(() {
initialMaximized = widget.controller.isMaximized();
nextIsMaximized = null;
});
}
if (widget.controller.isMinimized() != initialMinimized) {
setState(() {
initialMinimized = widget.controller.isMinimized();
nextIsMinized = null;
});
}
}

@override
void dispose() {
super.dispose();
widget.controller.removeListener(_onNotification);
}

@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text("Edit Window Properties"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: widthController,
keyboardType: TextInputType.number,
decoration: InputDecoration(labelText: "Width"),
),
TextButton(
onPressed: () {
double? width = double.tryParse(widthController.text);
double? height = double.tryParse(heightController.text);
String? title = titleController.text.isEmpty ? null : titleController.text;

onSave?.call(width, height, title);
Navigator.of(context).pop();
},
child: Text("Save"),
TextField(
controller: heightController,
keyboardType: TextInputType.number,
decoration: InputDecoration(labelText: "Height"),
),
TextField(
controller: titleController,
decoration: InputDecoration(labelText: "Title"),
),
CheckboxListTile(
title: const Text('Fullscreen'),
value: nextIsFullscreen ?? initialFullscreen,
onChanged: (bool? value) {
if (value != null) {
setState(() => nextIsFullscreen = value);
}
}),
CheckboxListTile(
title: const Text('Maximized'),
value: nextIsMaximized ?? initialMaximized,
onChanged: (bool? value) {
if (value != null) {
setState(() => nextIsMaximized = value);
}
}),
CheckboxListTile(
title: const Text('Minimized'),
value: nextIsMinized ?? initialMinimized,
onChanged: (bool? value) {
if (value != null) {
setState(() => nextIsMinized = value);
}
})
],
),
actions: [
TextButton(
onPressed: () => widget.onClose(),
child: Text("Cancel"),
),
TextButton(
onPressed: () => _onSave(),
child: Text("Save"),
),
],
);
}

void _onSave() {
double? width = double.tryParse(widthController.text);
double? height = double.tryParse(heightController.text);
String? title = titleController.text.isEmpty ? null : titleController.text;
if (width != null && height != null) {
widget.controller.updateContentSize(
WindowSizing(preferredSize: Size(width, height)),
);
},
);
}
if (title != null) {
widget.controller.setTitle(title);
}
if (nextIsFullscreen != null) {
if (widget.controller.isFullscreen() != nextIsFullscreen) {
widget.controller.setFullscreen(nextIsFullscreen!);
}
}
if (nextIsMaximized != null) {
if (widget.controller.isMaximized() != nextIsMaximized) {
widget.controller.setMaximized(nextIsMaximized!);
}
}
if (nextIsMinized != null) {
if (widget.controller.isMinimized() != nextIsMinized) {
widget.controller.setMinimized(nextIsMinized!);
}
}

widget.onClose();
}
}
Loading
Loading