Commit 903cdf5
Changed files (6)
lib
components
dialoges
settings
screens
subsettings
test
ui
components
lib/components/dialoges/oldinput_dialoge.dart
@@ -1,103 +0,0 @@
-import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
-import 'package:flutter_gen/gen_l10n/app_localizations.dart';
-
-// TODO: redo dialoges in flutter style
-@Deprecated('TODO: replace with new dialoge')
-class InputDialoge extends StatefulWidget {
- final String hintText;
- final String? initialValue;
-
- /// Gets called when the user submits the text field or presses the submit button.
- final void Function(String text) onSubmit;
- final List<TextInputFormatter>? inputFormatters;
- final TextInputType? keyboardType;
-
- const InputDialoge({super.key,
- required this.hintText,
- required this.onSubmit,
- this.inputFormatters,
- this.keyboardType,
- this.initialValue});
-
- @override
- State<InputDialoge> createState() => _InputDialogeState();
-}
-
-class _InputDialogeState extends State<InputDialoge> {
- final formKey = GlobalKey<FormState>();
- final controller = TextEditingController();
- final inputFocusNode = FocusNode();
-
- @override
- void dispose() {
- controller.dispose();
- super.dispose();
- }
-
-
- @override
- void initState() {
- super.initState();
- controller.text = widget.initialValue ?? '';
- }
-
- @override
- Widget build(BuildContext context) {
- inputFocusNode.requestFocus();
- return AlertDialog(
- content: TextFormField(
- key: formKey,
- focusNode: inputFocusNode,
- controller: controller,
- inputFormatters: widget.inputFormatters,
- keyboardType: widget.keyboardType,
- decoration: InputDecoration(
- hintText: widget.hintText
- ),
- onFieldSubmitted: widget.onSubmit,
- ),
- actions: [
- ElevatedButton(
- onPressed: () {
- widget.onSubmit(controller.text);
- },
- child: Text(AppLocalizations.of(context)!.btnConfirm)
- )
- ],
- );
- }
-}
-
-typedef NumberInputResult = void Function(double result);
-
-@Deprecated('TODO: replace with new dialoge')
-class NumberInputDialoge extends StatelessWidget {
- final String hintText;
- final NumberInputResult onParsableSubmit;
- final String? initialValue;
-
- const NumberInputDialoge({
- super.key,
- required this.hintText,
- required this.onParsableSubmit,
- this.initialValue});
-
- @override
- Widget build(BuildContext context) {
- return InputDialoge(
- hintText: hintText,
- inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'([0-9]+(\.([0-9]*))?)')),],
- keyboardType: TextInputType.number,
- initialValue: initialValue,
- onSubmit: (text) {
- double? value = double.tryParse(text);
- value ??= int.tryParse(text)?.toDouble();
- if (text.isEmpty || value == null) {
- return;
- }
- onParsableSubmit(value);
- }
- );
- }
-}
lib/components/settings/number_input_list_tile.dart
@@ -1,4 +1,4 @@
-import 'package:blood_pressure_app/components/dialoges/oldinput_dialoge.dart';
+import 'package:blood_pressure_app/components/dialoges/input_dialoge.dart';
import 'package:flutter/material.dart';
/// Widget for editing numbers in a list tile.
@@ -23,7 +23,7 @@ class NumberInputListTile extends StatelessWidget {
final num? value;
/// Gets called once the user submits a new valid number to the field.
- final NumberInputResult onParsableSubmit;
+ final void Function(double result) onParsableSubmit;
@override
Widget build(BuildContext context) {
@@ -32,18 +32,12 @@ class NumberInputListTile extends StatelessWidget {
subtitle: Text(value.toString()),
leading: leading,
trailing: const Icon(Icons.edit),
- onTap: () {
- showDialog(
- context: context,
- builder: (context) => NumberInputDialoge(
- initialValue: value?.toString(),
- hintText: label,
- onParsableSubmit: (value) {
- Navigator.of(context).pop();
- onParsableSubmit(value);
- },
- ),
+ onTap: () async {
+ final result = await showNumberInputDialoge(context,
+ initialValue: value,
+ hintText: label
);
+ if (result != null) onParsableSubmit(result);
},
);
}
lib/screens/subsettings/graph_markings.dart
@@ -1,5 +1,5 @@
import 'package:blood_pressure_app/components/color_picker.dart';
-import 'package:blood_pressure_app/components/dialoges/oldinput_dialoge.dart';
+import 'package:blood_pressure_app/components/dialoges/input_dialoge.dart';
import 'package:blood_pressure_app/model/horizontal_graph_line.dart';
import 'package:blood_pressure_app/model/storage/settings_store.dart';
import 'package:flutter/material.dart';
@@ -40,17 +40,10 @@ class GraphMarkingsScreen extends StatelessWidget {
onTap: () async {
final color = await showColorPickerDialog(context);
if (!context.mounted) return;
- final height = await showDialog<int>(context: context,
- builder: (context) => NumberInputDialoge(
- hintText: localizations.linePositionY,
- onParsableSubmit: (value) {
- Navigator.of(context).pop(value);
- }
- )
- );
+ final height = await showNumberInputDialoge(context, hintText: localizations.linePositionY);
if (color == null || height == null) return;
- lines.add(HorizontalGraphLine(color, height));
+ lines.add(HorizontalGraphLine(color, height.round()));
settings.horizontalGraphLines = lines;
},
);
lib/screens/settings.dart
@@ -2,7 +2,7 @@ import 'dart:io';
import 'package:blood_pressure_app/components/consistent_future_builder.dart';
import 'package:blood_pressure_app/components/dialoges/enter_timeformat.dart';
-import 'package:blood_pressure_app/components/dialoges/oldinput_dialoge.dart';
+import 'package:blood_pressure_app/components/dialoges/input_dialoge.dart';
import 'package:blood_pressure_app/components/settings/settings_widgets.dart';
import 'package:blood_pressure_app/model/blood_pressure.dart';
import 'package:blood_pressure_app/model/iso_lang_names.dart';
@@ -201,24 +201,14 @@ class SettingsPage extends StatelessWidget {
key: const Key('determineWarnValues'),
leading: const Icon(Icons.settings_applications_outlined),
title: Text(localizations.determineWarnValues),
- onTap: () {
- showDialog(
- context: context,
- builder: (context) => NumberInputDialoge(
- hintText: localizations.age,
- onParsableSubmit: (value) {
- int age = value.round();
- settings.sysWarn = BloodPressureWarnValues.getUpperSysWarnValue(age);
- settings.diaWarn = BloodPressureWarnValues.getUpperDiaWarnValue(age);
- Navigator.of(context).pop();
- Navigator.of(context).pop();
- Navigator.push(
- context,
- MaterialPageRoute(builder: (context) => const SettingsPage()),
- );
- },
- )
- );
+ onTap: () async {
+ final age = (await showNumberInputDialoge(context,
+ hintText: localizations.age,
+ ))?.round();
+ if (age != null) {
+ settings.sysWarn = BloodPressureWarnValues.getUpperSysWarnValue(age);
+ settings.diaWarn = BloodPressureWarnValues.getUpperDiaWarnValue(age);
+ }
},
),
ListTile(
test/ui/components/settings/input_list_tile_test.dart
@@ -1,4 +1,4 @@
-import 'package:blood_pressure_app/components/dialoges/oldinput_dialoge.dart';
+import 'package:blood_pressure_app/components/dialoges/input_dialoge.dart';
import 'package:blood_pressure_app/components/settings/input_list_tile.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
@@ -67,7 +67,8 @@ void main() {
await widgetTester.tap(find.byType(InputListTile));
await widgetTester.pumpAndSettle();
- await widgetTester.enterText(find.byType(TextFormField), 'changed');
+ expect(find.byType(TextField), findsOneWidget);
+ await widgetTester.enterText(find.byType(TextField), 'changed');
await widgetTester.tap(find.text('OK'));
await widgetTester.pumpAndSettle();
test/ui/components/settings/number_input_list_tile_test.dart
@@ -1,4 +1,4 @@
-import 'package:blood_pressure_app/components/dialoges/oldinput_dialoge.dart';
+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';
@@ -79,25 +79,29 @@ void main() {
expect(find.text('15'), findsOneWidget);
await widgetTester.tap(find.byType(NumberInputListTile));
await widgetTester.pumpAndSettle();
- await widgetTester.enterText(find.byType(TextFormField), '17');
+ expect(find.byType(TextField), findsOneWidget);
+ await widgetTester.enterText(find.byType(TextField), '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');
+ expect(find.byType(TextField), findsOneWidget);
+ await widgetTester.enterText(find.byType(TextField), '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');
+ expect(find.byType(TextField), findsOneWidget);
+ await widgetTester.enterText(find.byType(TextField), '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');
+ expect(find.byType(TextField), findsOneWidget);
+ await widgetTester.enterText(find.byType(TextField), '5.4');
await widgetTester.tap(find.text('OK'));
await widgetTester.pumpAndSettle();