import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../services/bluetooth_service.dart'; class PressureSettingsScreen extends ConsumerWidget { const PressureSettingsScreen({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final machineState = ref.watch(bluetoothServiceProvider); final bluetoothService = ref.read(bluetoothServiceProvider.notifier); return Scaffold( appBar: AppBar(title: const Text('Pressure Profiling')), body: ListView( padding: const EdgeInsets.all(16), children: [ _PressureSlider( label: 'Start Pressure (%)', value: machineState.pressureStart.toDouble(), min: 0, max: 100, onChanged: (v) => bluetoothService.updatePressureSettings(start: v.toInt()), ), _PressureSlider( label: 'End Pressure (%)', value: machineState.pressureEnd.toDouble(), min: 0, max: 100, onChanged: (v) => bluetoothService.updatePressureSettings(end: v.toInt()), ), _PressureSlider( label: 'Period (s)', value: machineState.pressurePeriod.toDouble(), min: 0, max: 60, onChanged: (v) => bluetoothService.updatePressureSettings(period: v.toInt()), ), const Divider(), const Padding( padding: EdgeInsets.all(16.0), child: Text( 'The pump will linearly transition from the start pressure to the end pressure over the specified period.', style: TextStyle(color: Colors.grey, fontSize: 14), textAlign: TextAlign.center, ), ), ], ), ); } } class _PressureSlider extends StatelessWidget { final String label; final double value; final double min; final double max; final ValueChanged onChanged; const _PressureSlider({ required this.label, required this.value, required this.min, required this.max, required this.onChanged, }); @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), child: Text( '$label: ${value.toInt()}${label.contains('%') ? '%' : 's'}', ), ), Slider( value: value.clamp(min, max), min: min, max: max, divisions: (max - min).toInt(), onChanged: onChanged, ), ], ); } }