-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathdevice_settings_container.dart
More file actions
107 lines (98 loc) · 3.05 KB
/
device_settings_container.dart
File metadata and controls
107 lines (98 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import 'package:dashbook/src/widgets/dashbook_icon.dart';
import 'package:dashbook/src/widgets/helpers.dart';
import 'package:dashbook/src/widgets/keys.dart';
import 'package:dashbook/src/widgets/select_device/custom_device.dart';
import 'package:dashbook/src/widgets/select_device/device_settings.dart';
import 'package:dashbook/src/widgets/select_device/select_device.dart';
import 'package:dashbook/src/widgets/side_bar_panel.dart';
import 'package:device_frame/device_frame.dart';
import 'package:flutter/material.dart';
class DeviceSettingsContainer extends StatefulWidget {
final VoidCallback onCancel;
const DeviceSettingsContainer({
required this.onCancel,
super.key,
});
@override
State<DeviceSettingsContainer> createState() =>
_DeviceSettingsContainerState();
}
class _DeviceSettingsContainerState extends State<DeviceSettingsContainer> {
final _formKey = GlobalKey<FormState>();
bool _isCustom = false;
void _setIsCustom(bool isCustom) {
setState(() {
_isCustom = isCustom;
DeviceSettings.of(context, listen: false).updateDevice(
isCustom ? Devices.android.largeTablet : null,
);
});
}
@override
Widget build(BuildContext context) {
return SideBarPanel(
title: 'Properties',
onCloseKey: kDevicePreviewCloseIcon,
width: sideBarSizeProperties(context),
onCancel: widget.onCancel,
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const _DeviceToggles(),
CheckboxListTile(
value: _isCustom,
key: kCustomDeviceToggle,
title: const Text('Custom device'),
contentPadding: EdgeInsets.zero,
onChanged: (value) => _setIsCustom(value!),
),
if (_isCustom)
CustomDevice(
formKey: _formKey,
changeToList: () {
_setIsCustom(false);
},
)
else
const SelectDevice(),
],
),
),
);
}
}
class _DeviceToggles extends StatelessWidget {
const _DeviceToggles();
@override
Widget build(BuildContext context) {
final deviceSettings = DeviceSettings.of(context);
return Row(
children: [
DashbookIcon(
key: kRotateIcon,
tooltip: 'Orientation',
icon: Icons.screen_rotation_outlined,
onClick: deviceSettings.settings.deviceInfo != null
? deviceSettings.rotate
: null,
),
DashbookIcon(
key: kHideFrameIcon,
tooltip: 'Device frame',
icon: Icons.mobile_off_outlined,
onClick: deviceSettings.settings.deviceInfo != null
? deviceSettings.toggleDeviceFrame
: null,
),
const Spacer(),
TextButton(
onPressed: deviceSettings.reset,
child: const Text('Reset'),
),
],
);
}
}