pressure_settings_screen.dart 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import '../services/bluetooth_service.dart';
  4. class PressureSettingsScreen extends ConsumerWidget {
  5. const PressureSettingsScreen({super.key});
  6. @override
  7. Widget build(BuildContext context, WidgetRef ref) {
  8. final machineState = ref.watch(bluetoothServiceProvider);
  9. final bluetoothService = ref.read(bluetoothServiceProvider.notifier);
  10. return Scaffold(
  11. appBar: AppBar(title: const Text('Pressure Profiling')),
  12. body: ListView(
  13. padding: const EdgeInsets.all(16),
  14. children: [
  15. _PressureSlider(
  16. label: 'Start Pressure (%)',
  17. value: machineState.pressureStart.toDouble(),
  18. min: 0,
  19. max: 100,
  20. onChanged: (v) =>
  21. bluetoothService.updatePressureSettings(start: v.toInt()),
  22. ),
  23. _PressureSlider(
  24. label: 'End Pressure (%)',
  25. value: machineState.pressureEnd.toDouble(),
  26. min: 0,
  27. max: 100,
  28. onChanged: (v) =>
  29. bluetoothService.updatePressureSettings(end: v.toInt()),
  30. ),
  31. _PressureSlider(
  32. label: 'Period (s)',
  33. value: machineState.pressurePeriod.toDouble(),
  34. min: 0,
  35. max: 60,
  36. onChanged: (v) =>
  37. bluetoothService.updatePressureSettings(period: v.toInt()),
  38. ),
  39. const Divider(),
  40. const Padding(
  41. padding: EdgeInsets.all(16.0),
  42. child: Text(
  43. 'The pump will linearly transition from the start pressure to the end pressure over the specified period.',
  44. style: TextStyle(color: Colors.grey, fontSize: 14),
  45. textAlign: TextAlign.center,
  46. ),
  47. ),
  48. ],
  49. ),
  50. );
  51. }
  52. }
  53. class _PressureSlider extends StatelessWidget {
  54. final String label;
  55. final double value;
  56. final double min;
  57. final double max;
  58. final ValueChanged<double> onChanged;
  59. const _PressureSlider({
  60. required this.label,
  61. required this.value,
  62. required this.min,
  63. required this.max,
  64. required this.onChanged,
  65. });
  66. @override
  67. Widget build(BuildContext context) {
  68. return Column(
  69. crossAxisAlignment: CrossAxisAlignment.start,
  70. children: [
  71. Padding(
  72. padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
  73. child: Text(
  74. '$label: ${value.toInt()}${label.contains('%') ? '%' : 's'}',
  75. ),
  76. ),
  77. Slider(
  78. value: value.clamp(min, max),
  79. min: min,
  80. max: max,
  81. divisions: (max - min).toInt(),
  82. onChanged: onChanged,
  83. ),
  84. ],
  85. );
  86. }
  87. }