Skip to content

Commit 6cff1dd

Browse files
committed
example: adding a modificatione example to the multi window reference app
1 parent 6ca09cd commit 6cff1dd

File tree

2 files changed

+124
-6
lines changed

2 files changed

+124
-6
lines changed

examples/multi_window_ref_app/lib/app/main_window.dart

+38-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:multi_window_ref_app/app/window_controller_render.dart';
44
import 'window_settings.dart';
55
import 'window_settings_dialog.dart';
66
import 'window_manager_model.dart';
7+
import 'regular_window_edit_dialog.dart';
78

89
class MainWindow extends StatefulWidget {
910
MainWindow({super.key, required WindowController mainController}) {
@@ -167,12 +168,43 @@ class _ActiveWindowsTable extends StatelessWidget {
167168
ListenableBuilder(
168169
listenable: controller.controller,
169170
builder: (BuildContext context, Widget? _) =>
170-
IconButton(
171-
icon: const Icon(Icons.delete_outlined),
172-
onPressed: () async {
173-
await controller.controller.destroy();
174-
},
175-
)),
171+
Row(children: [
172+
IconButton(
173+
icon: const Icon(Icons.edit_outlined),
174+
onPressed: () {
175+
if (controller.controller.type ==
176+
WindowArchetype.regular) {
177+
showRegularWindowEditDialog(context,
178+
initialWidth:
179+
controller.controller.size.width,
180+
initialHeight:
181+
controller.controller.size.height,
182+
initialTitle: "",
183+
initialState: (controller.controller
184+
as RegularWindowController)
185+
.state,
186+
onSave: (double? width, double? height,
187+
String? title, WindowState? state) {
188+
(controller.controller
189+
as RegularWindowController)
190+
.modify(
191+
size: width != null &&
192+
height != null
193+
? Size(width, height)
194+
: null,
195+
title: title,
196+
state: state);
197+
});
198+
}
199+
},
200+
),
201+
IconButton(
202+
icon: const Icon(Icons.delete_outlined),
203+
onPressed: () async {
204+
await controller.controller.destroy();
205+
},
206+
)
207+
])),
176208
),
177209
],
178210
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import 'package:flutter/material.dart';
2+
3+
void showRegularWindowEditDialog(BuildContext context,
4+
{double? initialWidth,
5+
double? initialHeight,
6+
String? initialTitle,
7+
WindowState? initialState,
8+
Function(double?, double?, String?, WindowState)? onSave}) {
9+
final TextEditingController widthController =
10+
TextEditingController(text: initialWidth?.toString() ?? '');
11+
final TextEditingController heightController =
12+
TextEditingController(text: initialHeight?.toString() ?? '');
13+
final TextEditingController titleController =
14+
TextEditingController(text: initialTitle ?? '');
15+
16+
showDialog(
17+
context: context,
18+
builder: (context) {
19+
WindowState selectedState = initialState ?? WindowState.restored;
20+
21+
return AlertDialog(
22+
title: Text("Edit Window Properties"),
23+
content: StatefulBuilder(
24+
builder: (context, setState) {
25+
return Column(
26+
mainAxisSize: MainAxisSize.min,
27+
children: [
28+
TextField(
29+
controller: widthController,
30+
keyboardType: TextInputType.number,
31+
decoration: InputDecoration(labelText: "Width"),
32+
),
33+
TextField(
34+
controller: heightController,
35+
keyboardType: TextInputType.number,
36+
decoration: InputDecoration(labelText: "Height"),
37+
),
38+
TextField(
39+
controller: titleController,
40+
decoration: InputDecoration(labelText: "Title"),
41+
),
42+
DropdownButton<WindowState>(
43+
value: selectedState,
44+
onChanged: (WindowState? newState) {
45+
if (newState != null) {
46+
setState(() {
47+
selectedState = newState;
48+
});
49+
}
50+
},
51+
items: WindowState.values.map((WindowState state) {
52+
return DropdownMenuItem<WindowState>(
53+
value: state,
54+
child: Text(
55+
state.toString().split('.').last[0].toUpperCase() +
56+
state.toString().split('.').last.substring(1),
57+
),
58+
);
59+
}).toList(),
60+
),
61+
],
62+
);
63+
},
64+
),
65+
actions: [
66+
TextButton(
67+
onPressed: () => Navigator.of(context).pop(),
68+
child: Text("Cancel"),
69+
),
70+
TextButton(
71+
onPressed: () {
72+
double? width = double.tryParse(widthController.text);
73+
double? height = double.tryParse(heightController.text);
74+
String? title =
75+
titleController.text.isEmpty ? null : titleController.text;
76+
77+
onSave?.call(width, height, title, selectedState);
78+
Navigator.of(context).pop();
79+
},
80+
child: Text("Save"),
81+
),
82+
],
83+
);
84+
},
85+
);
86+
}

0 commit comments

Comments
 (0)