-
Notifications
You must be signed in to change notification settings - Fork 848
Expand file tree
/
Copy pathselect_hardware.dart
More file actions
102 lines (91 loc) · 3.36 KB
/
Copy pathselect_hardware.dart
File metadata and controls
102 lines (91 loc) · 3.36 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
import 'package:flutter/material.dart';
import 'package:pslab/l10n/app_localizations.dart';
import 'package:pslab/providers/locator.dart';
import 'package:pslab/providers/board_state_provider.dart';
import 'package:pslab/view/widgets/main_scaffold_widget.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../theme/colors.dart';
class HardwareSelectionScreen extends StatefulWidget {
const HardwareSelectionScreen({super.key});
@override
State<HardwareSelectionScreen> createState() =>
_HardwareSelectionScreenState();
}
class _HardwareOption {
final String label;
final IconData icon;
final String value;
_HardwareOption(this.label, this.icon, this.value);
}
class _HardwareSelectionScreenState extends State<HardwareSelectionScreen> {
final AppLocalizations appLocalizations = getIt.get<AppLocalizations>();
late List<_HardwareOption> _options;
@override
void initState() {
super.initState();
_options = [
_HardwareOption(appLocalizations.psLabBoard, Icons.usb, "pslab_board"),
_HardwareOption(
appLocalizations.internalSensors, Icons.developer_board, "internal_sensors"),
];
}
Future<void> _selectHardware(String hardwareValue) async {
final boardProvider = getIt.get<BoardStateProvider>();
boardProvider.setHardware(hardwareValue);
final prefs = await SharedPreferences.getInstance();
await prefs.setString('selected_hardware', hardwareValue);
if (mounted) {
Navigator.pushReplacementNamed(context, '/');
}
}
@override
Widget build(BuildContext context) {
return MainScaffold(
index: 1,
title: appLocalizations.selectHardware,
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Center(
child: Image.asset(
'assets/icons/icon.png',
height: 100,
fit: BoxFit.contain,
),
),
const SizedBox(height: 40),
Text(
appLocalizations.selectHardwareQuestion,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 32),
..._options.map((option) => Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: ElevatedButton.icon(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 20),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
backgroundColor: primaryRed,
),
onPressed: () => _selectHardware(
option.value),
icon: Icon(option.icon, size: 28, color: chartTextColor,),
label: Text(option.label,
style: TextStyle(fontSize: 18, color: chartTextColor)),
),
)),
],
),
),
),
);
}
}