| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- 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,
- ),
- ),
- ],
- ),
- );
- }
- }
- /// Sends only on release; every `cmd set` rewrites controller EEPROM.
- class _PressureSlider extends StatefulWidget {
- final String label;
- final double value;
- final double min;
- final double max;
- final ValueChanged<double> onChanged;
- const _PressureSlider({
- required this.label,
- required this.value,
- required this.min,
- required this.max,
- required this.onChanged,
- });
- @override
- State<_PressureSlider> createState() => _PressureSliderState();
- }
- class _PressureSliderState extends State<_PressureSlider> {
- double? _draft;
- @override
- void didUpdateWidget(covariant _PressureSlider oldWidget) {
- super.didUpdateWidget(oldWidget);
- if (oldWidget.value != widget.value) _draft = null;
- }
- @override
- Widget build(BuildContext context) {
- final value = _draft ?? widget.value;
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
- child: Text(
- '${widget.label}: ${value.round()}${widget.label.contains('%') ? '%' : 's'}',
- ),
- ),
- Slider(
- value: value.clamp(widget.min, widget.max),
- min: widget.min,
- max: widget.max,
- divisions: (widget.max - widget.min).toInt(),
- onChanged: (v) => setState(() => _draft = v.roundToDouble()),
- onChangeEnd: (v) {
- setState(() => _draft = null);
- widget.onChanged(v.roundToDouble());
- },
- ),
- ],
- );
- }
- }
|