Commit 4e9ad39
Changed files (3)
app
lib
components
screens
app/lib/components/dialoges/add_measurement_dialoge.dart
@@ -1,5 +1,6 @@
import 'dart:math';
+import 'package:blood_pressure_app/components/bluetooth_input.dart';
import 'package:blood_pressure_app/components/date_time_picker.dart';
import 'package:blood_pressure_app/components/dialoges/fullscreen_dialoge.dart';
import 'package:blood_pressure_app/components/settings/settings_widgets.dart';
@@ -48,7 +49,11 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
final diaFocusNode = FocusNode();
final pulFocusNode = FocusNode();
final noteFocusNode = FocusNode();
+
late final TextEditingController sysController;
+ late final TextEditingController diaController;
+ late final TextEditingController pulController;
+ late final TextEditingController noteController;
/// Currently selected time.
@@ -96,9 +101,12 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
super.initState();
time = widget.initialRecord?.creationTime ?? DateTime.now();
needlePin = widget.initialRecord?.needlePin;
- sysController = TextEditingController(
- text: (widget.initialRecord?.systolic ?? '').toString(),
- );
+ sysController = TextEditingController();
+ diaController = TextEditingController();
+ pulController = TextEditingController();
+ noteController = TextEditingController();
+ _loadFields(widget.initialRecord);
+
if (widget.initialRecord != null) {
_measurementFormActive = true;
}
@@ -107,7 +115,6 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
ServicesBinding.instance.keyboard.addHandler(_onKey);
}
-
@override
void dispose() {
sysController.dispose();
@@ -119,6 +126,16 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
super.dispose();
}
+ /// Sets fields to values in a [record].
+ void _loadFields(BloodPressureRecord? record) {
+ time = record?.creationTime ?? DateTime.now();
+ if (record?.needlePin != null) needlePin = record?.needlePin;
+ if (record?.systolic != null) sysController.text = record!.systolic!.toString();
+ if (record?.diastolic != null) diaController.text = record!.diastolic!.toString();
+ if (record?.pulse != null) pulController.text = record!.pulse!.toString();
+ if (record?.notes != null) noteController.text = record!.notes;
+ }
+
bool _onKey(KeyEvent event) {
if (event is! KeyDownEvent) return false;
final isBackspace = event.logicalKey.keyId == 0x00100000008;
@@ -265,10 +282,14 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
child: ListView(
padding: const EdgeInsets.symmetric(horizontal: 8),
children: [
- // BleInput(), TODO: replace
+ // TODO: make toggleable in settings
+ BluetoothInput(
+ settings: widget.settings,
+ onMeasurement: (record) => setState(() => _loadFields(record)),
+ ),
TextButton(onPressed: () {
Clipboard.setData(ClipboardData(text: debugLog.join('\n')));
- }, child: Text('copy debug')),
+ }, child: Text('copy debug')), // TODO: remove
if (widget.settings.allowManualTimeInput)
_buildTimeInput(localizations),
Form(
@@ -289,7 +310,7 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
const SizedBox(width: 16,),
_buildValueInput(localizations,
labelText: localizations.diaLong,
- initialValue: widget.initialRecord?.diastolic,
+ controller: diaController,
onSaved: (value) =>
setState(() => diastolic = int.tryParse(value ?? '')),
focusNode: diaFocusNode,
@@ -306,7 +327,7 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
const SizedBox(width: 16,),
_buildValueInput(localizations,
labelText: localizations.pulLong,
- initialValue: widget.initialRecord?.pulse,
+ controller: pulController,
focusNode: pulFocusNode,
onSaved: (value) =>
setState(() => pulse = int.tryParse(value ?? '')),
@@ -316,7 +337,7 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: TextFormField(
- initialValue: widget.initialRecord?.notes,
+ controller: noteController,
focusNode: noteFocusNode,
decoration: InputDecoration(
labelText: localizations.addNote,
app/lib/components/bluetooth_input.dart
@@ -8,6 +8,7 @@ import 'package:blood_pressure_app/components/bluetooth_input/device_selection.d
import 'package:blood_pressure_app/components/bluetooth_input/input_card.dart';
import 'package:blood_pressure_app/components/bluetooth_input/measurement_failure.dart';
import 'package:blood_pressure_app/components/bluetooth_input/measurement_success.dart';
+import 'package:blood_pressure_app/model/blood_pressure/record.dart';
import 'package:blood_pressure_app/model/storage/storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -17,23 +18,25 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
/// Class for inputting measurement through bluetooth.
class BluetoothInput extends StatefulWidget {
/// Create a measurement input through bluetooth.
- const BluetoothInput({super.key, required this.settings});
+ const BluetoothInput({super.key,
+ required this.settings,
+ required this.onMeasurement,
+ });
/// Settings to store known devices.
final Settings settings;
+ /// Called when a measurement was received through bluetooth.
+ final void Function(BloodPressureRecord data) onMeasurement;
+
@override
State<BluetoothInput> createState() => _BluetoothInputState();
}
-// TODO: more info
-// TODO: make toggleable in settings
class _BluetoothInputState extends State<BluetoothInput> {
/// Whether the user expanded bluetooth input
bool _isActive = false;
- // TODO: return values
-
final BluetoothCubit _bluetoothCubit = BluetoothCubit();
StreamSubscription<BluetoothState>? _bluetoothSubscription;
DeviceScanCubit? _deviceScanCubit;
app/lib/screens/home_screen.dart
@@ -1,4 +1,3 @@
-import 'package:blood_pressure_app/components/bluetooth_input.dart';
import 'package:blood_pressure_app/components/dialoges/add_measurement_dialoge.dart';
import 'package:blood_pressure_app/components/measurement_list/measurement_list.dart';
import 'package:blood_pressure_app/model/blood_pressure/medicine/intake_history.dart';
@@ -66,7 +65,6 @@ class AppHome extends StatelessWidget {
Consumer<IntervallStoreManager>(builder: (context, intervalls, child) =>
Consumer<Settings>(builder: (context, settings, child) =>
Column(children: [
- BluetoothInput(settings: Settings(),),
const MeasurementGraph(),
Expanded(
child: (settings.useLegacyList) ?