@@ -5,6 +5,7 @@ import 'package:pslab/providers/gas_sensor_state_provider.dart';
55import 'package:pslab/theme/colors.dart' ;
66
77import '../../l10n/app_localizations.dart' ;
8+ import '../../providers/gas_sensor_config_provider.dart' ;
89import '../../providers/locator.dart' ;
910
1011class 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