|
| 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