Commit 8211937
Changed files (5)
app
lib
components
l10n
test
ui
components
bluetooth_input
app/lib/components/bluetooth_input/closed_bluetooth_input.dart
@@ -11,7 +11,6 @@ class ClosedBluetoothInput extends StatelessWidget {
required this.onStarted,
this.inputInfo,
});
- // TODO: test
/// State update provider and interaction with the device.
final BluetoothCubit bluetoothCubit;
app/lib/components/bluetooth_input/measurement_failure.dart
@@ -0,0 +1,36 @@
+import 'package:blood_pressure_app/components/bluetooth_input/input_card.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+
+/// Indication of a failure while taking a bluetooth measurement.
+class MeasurementFailure extends StatelessWidget {
+ /// Indicate a failure while taking a bluetooth measurement.
+ const MeasurementFailure({super.key, required this.onTap});
+
+ /// Called when the user requests closing.
+ final void Function() onTap;
+
+ // TODO: test
+
+ @override
+ Widget build(BuildContext context) => GestureDetector(
+ onTap: onTap,
+ child: InputCard(
+ onClosed: onTap,
+ child: Center(
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ const Icon(Icons.error_outline, color: Colors.red),
+ const SizedBox(height: 8,),
+ Text(AppLocalizations.of(context)!.errMeasurementRead),
+ const SizedBox(height: 4,),
+ Text(AppLocalizations.of(context)!.tapToClose),
+ const SizedBox(height: 8,),
+ ],
+ ),
+ ),
+ ),
+ );
+
+}
app/lib/components/bluetooth_input.dart
@@ -6,6 +6,7 @@ import 'package:blood_pressure_app/bluetooth/device_scan_cubit.dart';
import 'package:blood_pressure_app/components/bluetooth_input/closed_bluetooth_input.dart';
import 'package:blood_pressure_app/components/bluetooth_input/device_selection.dart';
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/model/storage/storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -77,17 +78,8 @@ class _BluetoothInputState extends State<BluetoothInput> {
builder: (BuildContext context, BleReadState state) => switch (state) {
BleReadInProgress() => _buildMainCard(context,
child: const CircularProgressIndicator()),
- BleReadFailure() => _buildMainCard(context,
- child: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- const Icon(Icons.error_outline, color: Colors.red),
- const SizedBox(height: 8,),
- Text(AppLocalizations.of(context)!.errMeasurementRead),
- ],
- ),
- ),
+ BleReadFailure() => MeasurementFailure(
+ onTap: _returnToIdle,
),
BleReadSuccess() => _buildMainCard(context,
child: Center(
app/lib/l10n/app_en.arb
@@ -517,7 +517,7 @@
"@errBleNoDev": {},
"bluetoothDisabled": "Bluetooth disabled",
"@bluetoothDisabled": {},
- "errMeasurementRead": "Error reading measurement",
+ "errMeasurementRead": "Error reading measurement!",
"@errBluetooth": {},
"measurementSuccess": "Measurement taken successfully",
"@measurementSuccess": {},
@@ -528,5 +528,7 @@
"aboutBleInput": "Some measurement devices are BLE GATT compatible. You can pair these devices here and automatically transmit measurements or disable this option in the settings.",
"@aboutBleInput": {},
"scanningForDevices": "Scanning for devices",
- "@scanningForDevices": {}
+ "@scanningForDevices": {},
+ "tapToClose": "Tap to close.",
+ "@tapToClose": {}
}
app/test/ui/components/bluetooth_input/measurement_failure_test.dart
@@ -0,0 +1,31 @@
+
+import 'package:blood_pressure_app/components/bluetooth_input/measurement_failure.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+import '../util.dart';
+
+
+void main() {
+ testWidgets('should show states correctly', (WidgetTester tester) async {
+ int tapCount = 0;
+ await tester.pumpWidget(materialApp(MeasurementFailure(
+ onTap: () => tapCount++,
+ )));
+
+ expect(find.byIcon(Icons.error_outline), findsOneWidget);
+ expect(find.byIcon(Icons.close), findsOneWidget);
+ final localizations = await AppLocalizations.delegate.load(const Locale('en'));
+ expect(find.text(localizations.errMeasurementRead), findsOneWidget);
+ expect(find.text(localizations.tapToClose), findsOneWidget);
+
+ expect(tapCount, 0);
+ await tester.tap(find.text(localizations.tapToClose));
+ await tester.pump();
+ expect(tapCount, 1);
+ await tester.tap(find.byIcon(Icons.close));
+ await tester.pump();
+ expect(tapCount, 2);
+ });
+}