Skip to content

Commit 680689c

Browse files
rahul31124marcnause
authored andcommitted
updated config UI
1 parent 4c39a81 commit 680689c

2 files changed

Lines changed: 86 additions & 50 deletions

File tree

lib/view/gas_sensor_config_screen.dart

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,44 +61,10 @@ class _GasSensorConfigScreenState extends State<GasSensorConfigScreen> {
6161
_isControllerInitialized = true;
6262
}
6363

64-
String currentMode = provider.config.activeGas;
65-
final List<String> allowedModes = [
66-
'Raw',
67-
'CO2',
68-
'NH3',
69-
'Alcohol',
70-
'CO',
71-
'Toluene',
72-
'Acetone'
73-
];
74-
75-
if (!allowedModes.contains(currentMode)) {
76-
currentMode = 'Raw';
77-
}
78-
7964
return SingleChildScrollView(
8065
child: Column(
8166
crossAxisAlignment: CrossAxisAlignment.start,
8267
children: [
83-
ConfigDropdownItem(
84-
title: "Active Gas",
85-
selectedValue: currentMode,
86-
options: [
87-
ConfigOption(value: 'Raw', displayName: 'Raw'),
88-
ConfigOption(value: 'CO2', displayName: 'CO2'),
89-
ConfigOption(value: 'NH3', displayName: 'NH3'),
90-
ConfigOption(
91-
value: 'Alcohol', displayName: 'Alcohol'),
92-
ConfigOption(value: 'CO', displayName: 'CO'),
93-
ConfigOption(
94-
value: 'Toluene', displayName: 'Toluene'),
95-
ConfigOption(
96-
value: 'Acetone', displayName: 'Acetone'),
97-
],
98-
onChanged: (value) {
99-
provider.updateActiveGas(value);
100-
},
101-
),
10268
ConfigInputItem(
10369
title: appLocalizations.updatePeriod,
10470
value:

lib/view/widgets/gas_sensor_card.dart

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:pslab/providers/gas_sensor_state_provider.dart';
55
import 'package:pslab/theme/colors.dart';
66

77
import '../../l10n/app_localizations.dart';
8+
import '../../providers/gas_sensor_config_provider.dart';
89
import '../../providers/locator.dart';
910

1011
class GasSensorCard extends StatefulWidget {
@@ -46,7 +47,18 @@ class _GasSensorCardState extends State<GasSensorCard> {
4647

4748
double maxScaleLimit = mode == 'Raw' ? 1024.0 : 5000.0;
4849
double currentValue = provider.getCurrentValue().clamp(0.0, maxScaleLimit);
49-
String activeGasName = provider.getActiveMode();
50+
51+
final List<String> allowedModes = [
52+
'Raw',
53+
'CO2',
54+
'NH3',
55+
'Alcohol',
56+
'CO',
57+
'Toluene',
58+
'Acetone'
59+
];
60+
61+
String currentMode = allowedModes.contains(mode) ? mode : 'Raw';
5062

5163
return Column(
5264
children: [
@@ -59,9 +71,7 @@ class _GasSensorCardState extends State<GasSensorCard> {
5971
children: [
6072
GxRadialGauge(
6173
value: GaugeValue(
62-
value: currentValue,
63-
min: 0,
64-
max: mode == 'Raw' ? 1024 : 5000),
74+
value: currentValue, min: 0, max: maxScaleLimit),
6575
size: const Size(220, 220),
6676
startAngleInDegree: 140,
6777
sweepAngleInDegree: 260,
@@ -149,19 +159,79 @@ class _GasSensorCardState extends State<GasSensorCard> {
149159
),
150160
),
151161
const SizedBox(height: 8),
152-
Container(
153-
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
154-
decoration: BoxDecoration(
155-
color: Colors.white.withValues(alpha: 0.1),
156-
borderRadius: BorderRadius.circular(20),
162+
PopupMenuButton<String>(
163+
initialValue: currentMode,
164+
color: Colors.white,
165+
position: PopupMenuPosition.under,
166+
constraints: const BoxConstraints(minWidth: 160, maxWidth: 160),
167+
shape: RoundedRectangleBorder(
168+
borderRadius: BorderRadius.circular(12),
157169
),
158-
child: Text(
159-
activeGasName.toUpperCase(),
160-
style: const TextStyle(
161-
fontSize: 14,
162-
fontWeight: FontWeight.w800,
163-
color: Colors.black87,
164-
letterSpacing: 1.2,
170+
onSelected: (String newValue) {
171+
provider.setActiveMode(newValue);
172+
Provider.of<GasSensorConfigProvider>(context, listen: false)
173+
.updateActiveGas(newValue);
174+
},
175+
itemBuilder: (BuildContext context) {
176+
return allowedModes.map((String value) {
177+
return PopupMenuItem<String>(
178+
value: value,
179+
child: Center(
180+
child: Text(
181+
value.toUpperCase(),
182+
style: const TextStyle(
183+
fontSize: 13,
184+
fontWeight: FontWeight.w700,
185+
color: Colors.black87,
186+
letterSpacing: 1.2,
187+
),
188+
),
189+
),
190+
);
191+
}).toList();
192+
},
193+
child: SizedBox(
194+
width: 160,
195+
height: 36,
196+
child: Stack(
197+
children: [
198+
Align(
199+
alignment: Alignment.center,
200+
child: Text(
201+
currentMode.toUpperCase(),
202+
style: const TextStyle(
203+
fontSize: 14,
204+
fontWeight: FontWeight.w800,
205+
color: Colors.black87,
206+
letterSpacing: 1.2,
207+
),
208+
),
209+
),
210+
Align(
211+
alignment: Alignment.centerRight,
212+
child: Container(
213+
width: 32,
214+
height: 32,
215+
decoration: BoxDecoration(
216+
color: Colors.white,
217+
borderRadius: BorderRadius.circular(8),
218+
border: Border.all(color: Colors.black12, width: 1.2),
219+
boxShadow: [
220+
BoxShadow(
221+
color: Colors.black.withValues(alpha: 0.02),
222+
blurRadius: 2,
223+
offset: const Offset(0, 1),
224+
)
225+
],
226+
),
227+
child: const Icon(
228+
Icons.keyboard_arrow_down,
229+
color: Colors.black87,
230+
size: 20,
231+
),
232+
),
233+
),
234+
],
165235
),
166236
),
167237
),

0 commit comments

Comments
 (0)