-
-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathnode_screen.dart
More file actions
314 lines (298 loc) · 12.2 KB
/
node_screen.dart
File metadata and controls
314 lines (298 loc) · 12.2 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../app.dart';
import '../providers/node_provider.dart';
import '../services/preferences_service.dart';
import '../widgets/node_controls.dart';
class NodeScreen extends StatefulWidget {
const NodeScreen({super.key});
@override
State<NodeScreen> createState() => _NodeScreenState();
}
class _NodeScreenState extends State<NodeScreen> {
final _hostController = TextEditingController();
final _portController = TextEditingController();
final _tokenController = TextEditingController();
bool _isLocal = true;
bool _loading = true;
@override
void initState() {
super.initState();
_loadSettings();
}
Future<void> _loadSettings() async {
final prefs = PreferencesService();
await prefs.init();
final host = prefs.nodeGatewayHost ?? '127.0.0.1';
final port = prefs.nodeGatewayPort ?? 18789;
final token = prefs.nodeGatewayToken ?? '';
setState(() {
_isLocal = host == '127.0.0.1' || host == 'localhost';
_hostController.text = _isLocal ? '' : host;
_portController.text = _isLocal ? '' : '$port';
_tokenController.text = _isLocal ? '' : token;
_loading = false;
});
}
@override
void dispose() {
_hostController.dispose();
_portController.dispose();
_tokenController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(title: const Text('Node Configuration')),
body: _loading
? const Center(child: CircularProgressIndicator())
: Consumer<NodeProvider>(
builder: (context, provider, _) {
final state = provider.state;
return ListView(
padding: const EdgeInsets.all(16),
children: [
const NodeControls(),
const SizedBox(height: 16),
// Gateway Connection
_sectionHeader(theme, 'GATEWAY CONNECTION'),
Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RadioListTile<bool>(
title: const Text('Local Gateway'),
subtitle: const Text('Auto-pair with gateway on this device'),
value: true,
groupValue: _isLocal,
onChanged: (value) {
setState(() => _isLocal = value!);
},
),
RadioListTile<bool>(
title: const Text('Remote Gateway'),
subtitle: const Text('Connect to a gateway on another device'),
value: false,
groupValue: _isLocal,
onChanged: (value) {
setState(() => _isLocal = value!);
},
),
if (!_isLocal) ...[
const SizedBox(height: 12),
TextField(
controller: _hostController,
decoration: const InputDecoration(
labelText: 'Gateway Host',
hintText: '192.168.1.100',
),
),
const SizedBox(height: 12),
TextField(
controller: _portController,
decoration: const InputDecoration(
labelText: 'Gateway Port',
hintText: '18789',
),
keyboardType: TextInputType.number,
),
const SizedBox(height: 12),
TextField(
controller: _tokenController,
decoration: const InputDecoration(
labelText: 'Gateway Token',
hintText: 'Paste token from gateway dashboard URL',
helperText: 'Found in dashboard URL after #token=',
prefixIcon: Icon(Icons.key),
),
obscureText: true,
),
const SizedBox(height: 12),
FilledButton.icon(
onPressed: () {
final host = _hostController.text.trim();
final port = int.tryParse(_portController.text.trim()) ?? 18789;
final token = _tokenController.text.trim();
if (host.isNotEmpty) {
provider.connectRemote(host, port,
token: token.isNotEmpty ? token : null);
}
},
icon: const Icon(Icons.link),
label: const Text('Connect'),
),
],
],
),
),
),
const SizedBox(height: 16),
// Pairing Status
if (state.pairingCode != null) ...[
_sectionHeader(theme, 'PAIRING'),
Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
const Icon(Icons.qr_code, size: 48),
const SizedBox(height: 8),
Text(
'Approve this code on the gateway:',
style: theme.textTheme.bodyMedium,
),
const SizedBox(height: 8),
SelectableText(
state.pairingCode!,
style: theme.textTheme.headlineMedium?.copyWith(
fontFamily: 'monospace',
fontWeight: FontWeight.bold,
color: theme.colorScheme.primary,
),
),
],
),
),
),
const SizedBox(height: 16),
],
// Capabilities
_sectionHeader(theme, 'CAPABILITIES'),
_capabilityTile(
theme,
'Camera',
'Capture photos and video clips',
Icons.camera_alt,
),
_capabilityTile(
theme,
'Canvas',
'Navigate and interact with web pages',
Icons.web,
),
_capabilityTile(
theme,
'Location',
'Get device GPS coordinates',
Icons.location_on,
),
_capabilityTile(
theme,
'Screen Recording',
'Record device screen (requires consent each time)',
Icons.screen_share,
),
_capabilityTile(
theme,
'Flashlight',
'Toggle device torch on/off',
Icons.flashlight_on,
),
_capabilityTile(
theme,
'Vibration',
'Trigger haptic feedback and vibration patterns',
Icons.vibration,
),
_capabilityTile(
theme,
'Sensors',
'Read accelerometer, gyroscope, magnetometer, barometer',
Icons.sensors,
),
_capabilityTile(
theme,
'Bluetooth Serial',
'Connect to Micro:bit, HC-05 and classic BT serial devices',
Icons.bluetooth,
),
_capabilityTile(
theme,
'USB Serial',
'Wired serial via USB OTG (Arduino, Micro:bit, FTDI)',
Icons.usb,
),
const SizedBox(height: 16),
// Device Info
if (state.deviceId != null) ...[
_sectionHeader(theme, 'DEVICE INFO'),
ListTile(
title: const Text('Device ID'),
subtitle: SelectableText(
state.deviceId!,
style: const TextStyle(fontFamily: 'monospace', fontSize: 12),
),
leading: const Icon(Icons.fingerprint),
),
],
const SizedBox(height: 16),
// Logs
_sectionHeader(theme, 'NODE LOGS'),
Card(
child: Container(
height: 200,
padding: const EdgeInsets.all(12),
child: state.logs.isEmpty
? Center(
child: Text(
'No logs yet',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
)
: ListView.builder(
reverse: true,
itemCount: state.logs.length,
itemBuilder: (context, index) {
final log = state.logs[state.logs.length - 1 - index];
return Text(
log,
style: const TextStyle(
fontFamily: 'monospace',
fontSize: 11,
),
);
},
),
),
),
],
);
},
),
);
}
Widget _sectionHeader(ThemeData theme, String title) {
return Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 8),
child: Text(
title,
style: theme.textTheme.labelSmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
fontWeight: FontWeight.w600,
letterSpacing: 1.2,
),
),
);
}
Widget _capabilityTile(
ThemeData theme, String title, String subtitle, IconData icon) {
return Card(
child: ListTile(
leading: Icon(icon, color: theme.colorScheme.onSurfaceVariant),
title: Text(title),
subtitle: Text(subtitle),
trailing: const Icon(
Icons.check_circle,
color: AppColors.statusGreen,
size: 20,
),
),
);
}
}