Commit 1036ae6
Changed files (4)
lib
components
settings
screens
subsettings
test
ui
components
settings
lib/components/settings/number_input_list_tile.dart
@@ -8,7 +8,7 @@ class NumberInputListTile extends StatelessWidget {
{super.key,
required this.label,
this.leading,
- this.initialValue,
+ this.value,
required this.onParsableSubmit,});
/// Short label describing the required field contents.
@@ -19,8 +19,8 @@ class NumberInputListTile extends StatelessWidget {
/// Widget to display before the label in the list tile.
final Widget? leading;
- /// Initial content of the input field.
- final num? initialValue;
+ /// Current content of the input field.
+ final num? value;
/// Gets called once the user submits a new valid number to the field.
final NumberInputResult onParsableSubmit;
@@ -29,14 +29,14 @@ class NumberInputListTile extends StatelessWidget {
Widget build(BuildContext context) {
return ListTile(
title: Text(label),
- subtitle: Text(initialValue.toString()),
+ subtitle: Text(value.toString()),
leading: leading,
trailing: const Icon(Icons.edit),
onTap: () {
showDialog(
context: context,
builder: (context) => NumberInputDialoge(
- initialValue: initialValue?.toString(),
+ initialValue: value?.toString(),
hintText: label,
onParsableSubmit: (value) {
Navigator.of(context).pop();
lib/screens/subsettings/export_import_screen.dart
@@ -127,28 +127,28 @@ class ExportImportScreen extends StatelessWidget {
Column(
children: [
NumberInputListTile(
- initialValue: pdfExportSettings.headerHeight,
+ value: pdfExportSettings.headerHeight,
label: localizations.exportPdfHeaderHeight,
onParsableSubmit: (value) {
pdfExportSettings.headerHeight = value;
},
),
NumberInputListTile(
- initialValue: pdfExportSettings.cellHeight,
+ value: pdfExportSettings.cellHeight,
label: localizations.exportPdfCellHeight,
onParsableSubmit: (value) {
pdfExportSettings.cellHeight = value;
},
),
NumberInputListTile(
- initialValue: pdfExportSettings.headerFontSize,
+ value: pdfExportSettings.headerFontSize,
label: localizations.exportPdfHeaderFontSize,
onParsableSubmit: (value) {
pdfExportSettings.headerFontSize = value;
},
),
NumberInputListTile(
- initialValue: pdfExportSettings.cellFontSize,
+ value: pdfExportSettings.cellFontSize,
label: localizations.exportPdfCellFontSize,
onParsableSubmit: (value) {
pdfExportSettings.cellFontSize = value;
lib/screens/settings.dart
@@ -170,7 +170,7 @@ class SettingsPage extends StatelessWidget {
key: const Key('sysWarn'),
label: localizations.sysWarn,
leading: const Icon(Icons.warning_amber_outlined),
- initialValue: settings.sysWarn,
+ value: settings.sysWarn,
onParsableSubmit: (double value) {
settings.sysWarn = value.round();
},
@@ -179,7 +179,7 @@ class SettingsPage extends StatelessWidget {
key: const Key('diaWarn'),
label: localizations.diaWarn,
leading: const Icon(Icons.warning_amber_outlined),
- initialValue: settings.diaWarn,
+ value: settings.diaWarn,
onParsableSubmit: (double value) {
settings.diaWarn = value.round();
},
test/ui/components/settings/number_input_list_tile_test.dart
@@ -0,0 +1,115 @@
+import 'package:blood_pressure_app/components/dialoges/input_dialoge.dart';
+import 'package:blood_pressure_app/components/settings/number_input_list_tile.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+void main() {
+ group('NumberInputListTile', () {
+ testWidgets('should show fields', (widgetTester) async {
+ await widgetTester.pumpWidget(_materialApp(NumberInputListTile(
+ label: 'test title',
+ value: 15,
+ onParsableSubmit: (double newValue) {
+ assert(false, 'should not be called');
+ },
+ )));
+ expect(find.text('test title'), findsOneWidget);
+ expect(find.text('15'), findsOneWidget);
+ });
+ testWidgets('should allow canceling edit', (widgetTester) async {
+ await widgetTester.pumpWidget(_materialApp(NumberInputListTile(
+ label: 'test title',
+ value: 15,
+ onParsableSubmit: (double newValue) {
+ assert(false, 'should not be called');
+ },
+ )));
+
+ expect(find.byType(InputDialoge), findsNothing);
+ await widgetTester.tap(find.byType(NumberInputListTile));
+ await widgetTester.pumpAndSettle();
+
+ expect(find.byType(InputDialoge), findsOneWidget);
+ await widgetTester.tapAt(const Offset(0, 0));
+ await widgetTester.pumpAndSettle();
+
+ expect(find.byType(InputDialoge), findsNothing);
+ });
+ testWidgets('should prefill value on edit', (widgetTester) async {
+ await widgetTester.pumpWidget(_materialApp(NumberInputListTile(
+ label: 'test title',
+ value: 15,
+ onParsableSubmit: (double newValue) {
+ assert(false, 'should not be called');
+ },
+ )));
+
+ expect(find.text('15'), findsOneWidget);
+ await widgetTester.tap(find.byType(NumberInputListTile));
+ await widgetTester.pumpAndSettle();
+
+ expect(find.text('15'), findsNWidgets(2));
+ });
+ testWidgets('should allow editing values', (widgetTester) async {
+ int callCount = 0;
+ await widgetTester.pumpWidget(_materialApp(NumberInputListTile(
+ label: 'test title',
+ value: 15,
+ onParsableSubmit: (double newValue) {
+ callCount += 1;
+ switch (callCount) {
+ case 1:
+ expect(newValue, 17.0);
+ break;
+ case 2:
+ expect(newValue, 15.0);
+ break;
+ case 3:
+ expect(newValue, 0.123);
+ break;
+ case 4:
+ expect(newValue, 5.4);
+ break;
+ }
+ },
+ )));
+
+ expect(find.text('15'), findsOneWidget);
+ await widgetTester.tap(find.byType(NumberInputListTile));
+ await widgetTester.pumpAndSettle();
+ await widgetTester.enterText(find.byType(TextFormField), '17');
+ await widgetTester.tap(find.text('OK'));
+ await widgetTester.pumpAndSettle();
+
+ await widgetTester.tap(find.byType(NumberInputListTile));
+ await widgetTester.pumpAndSettle();
+ await widgetTester.enterText(find.byType(TextFormField), '15.0');
+ await widgetTester.tap(find.text('OK'));
+ await widgetTester.pumpAndSettle();
+
+ await widgetTester.tap(find.byType(NumberInputListTile));
+ await widgetTester.pumpAndSettle();
+ await widgetTester.enterText(find.byType(TextFormField), '0.123');
+ await widgetTester.tap(find.text('OK'));
+ await widgetTester.pumpAndSettle();
+
+ await widgetTester.tap(find.byType(NumberInputListTile));
+ await widgetTester.pumpAndSettle();
+ await widgetTester.enterText(find.byType(TextFormField), '5.4');
+ await widgetTester.tap(find.text('OK'));
+ await widgetTester.pumpAndSettle();
+
+ expect(find.byType(InputDialoge), findsNothing);
+ expect(callCount, 4);
+ });
+ });
+}
+
+Widget _materialApp(Widget child) {
+ return MaterialApp(
+ localizationsDelegates: const [AppLocalizations.delegate,],
+ locale: const Locale('en'),
+ home: Scaffold(body:child),
+ );
+}
\ No newline at end of file