-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdevice.dart
164 lines (152 loc) · 5.26 KB
/
device.dart
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import 'package:ensemble_device_preview/src/state/store.dart';
import 'package:ensemble_device_preview/src/views/tool_panel/sections/subsections/device_model.dart';
import 'package:ensemble_device_preview/src/views/tool_panel/widgets/device_type_icon.dart';
import 'package:ensemble_device_preview/src/views/tool_panel/widgets/target_platform_icon.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:provider/provider.dart';
import 'section.dart';
/// All the simulated properties for the device.
class DeviceSection extends StatelessWidget {
/// Create a new menu section with simulated device properties.
///
/// The items can be hidden with [model], [orientation], [frameVisibility],
/// [virtualKeyboard] parameters.
const DeviceSection({
Key? key,
this.model = true,
this.orientation = true,
this.frameVisibility = true,
this.virtualKeyboard = true,
}) : super(key: key);
/// Allow to edit the current simulated model.
final bool model;
/// Allow to edit the current simulated device orientation.
final bool orientation;
/// Allow to hide or show the device frame.
final bool frameVisibility;
/// Allow to show or hide a software keyboard mockup.
final bool virtualKeyboard;
@override
Widget build(BuildContext context) {
final deviceName = context.select(
(DevicePreviewStore store) => store.deviceInfo.name,
);
final deviceIdentifier = context.select(
(DevicePreviewStore store) => store.deviceInfo.identifier,
);
final canRotate = context.select(
(DevicePreviewStore store) => store.deviceInfo.rotatedSafeAreas != null,
);
final orientation = context.select(
(DevicePreviewStore store) => store.data.orientation,
);
final isVirtualKeyboardVisible = context.select(
(DevicePreviewStore store) => store.data.isVirtualKeyboardVisible,
);
final isFrameVisible = context.select(
(DevicePreviewStore store) => store.data.isFrameVisible,
);
return ToolPanelSection(
title: 'Device',
children: [
if (model)
ListTile(
key: const Key('model'),
title: const Text('Model'),
subtitle: Text(deviceName),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
TargetPlatformIcon(
platform: deviceIdentifier.platform,
),
const SizedBox(
width: 8,
),
DeviceTypeIcon(
type: deviceIdentifier.type,
),
const Icon(Icons.chevron_right_rounded),
],
),
onTap: () {
final theme = Theme.of(context);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Theme(
data: theme,
child: const DeviceModelPicker(),
),
),
);
},
),
if (this.orientation && canRotate)
ListTile(
key: const Key('orientation'),
title: const Text('Orientation'),
subtitle: Text(
() {
switch (orientation) {
case Orientation.landscape:
return 'Landscape';
case Orientation.portrait:
return 'Portrait';
}
}(),
),
trailing: AnimatedContainer(
duration: const Duration(milliseconds: 200),
transformAlignment: Alignment.center,
transform: Matrix4.rotationZ(
orientation == Orientation.landscape ? 2.35 : 0.75,
),
child: const Icon(Icons.screen_rotation),
),
onTap: () {
final state = context.read<DevicePreviewStore>();
state.rotate();
},
),
if (frameVisibility)
ListTile(
key: const Key('frame'),
title: const Text('Frame visibility'),
subtitle: Text(isFrameVisible ? 'Visible' : 'Hidden'),
trailing: Opacity(
opacity: isFrameVisible ? 1.0 : 0.3,
child: Icon(
isFrameVisible
? Icons.border_outer_rounded
: Icons.border_clear_rounded,
),
),
onTap: () {
final state = context.read<DevicePreviewStore>();
state.toggleFrame();
},
),
if (virtualKeyboard)
ListTile(
key: const Key('keyboard'),
title: const Text('Virtual keyboard preview'),
subtitle: Text(isVirtualKeyboardVisible ? 'Visible' : 'Hidden'),
trailing: Opacity(
opacity: isVirtualKeyboardVisible ? 1.0 : 0.3,
child: Icon(
isVirtualKeyboardVisible
? Icons.keyboard
: Icons.keyboard_outlined,
),
),
onTap: () {
final state = context.read<DevicePreviewStore>();
state.toggleVirtualKeyboard();
},
),
],
);
}
}