Commit 5931bbf

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2023-11-10 14:42:13
focus first on dialog open
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 00a20f7
Changed files (2)
lib
components
screens
lib/components/dialoges/add_measurement.dart
@@ -33,6 +33,7 @@ class AddMeasurementDialoge extends StatefulWidget {
 
 class _AddMeasurementDialogeState extends State<AddMeasurementDialoge> {
   final formKey = GlobalKey<FormState>();
+  final firstFocusNode = FocusNode();
 
   /// Currently selected time.
   late DateTime time;
@@ -57,6 +58,15 @@ class _AddMeasurementDialogeState extends State<AddMeasurementDialoge> {
     super.initState();
     time = widget.initialRecord?.creationTime ?? DateTime.now();
     needlePin = widget.initialRecord?.needlePin;
+
+    firstFocusNode.requestFocus();
+  }
+
+
+  @override
+  void dispose() {
+    firstFocusNode.dispose();
+    super.dispose();
   }
 
   Widget buildTimeInput(AppLocalizations localizations) =>
@@ -100,13 +110,14 @@ class _AddMeasurementDialogeState extends State<AddMeasurementDialoge> {
     int? initialValue,
     String? hintText,
     void Function(String?)? onSaved,
-    // FocusNode? focusNode, TODO: check if works without
+    FocusNode? focusNode,
   }) {
     return Expanded(
       child: TextFormField(
         initialValue: (initialValue ?? '').toString(),
         decoration: getInputDecoration(hintText),
         keyboardType: TextInputType.number,
+        focusNode: focusNode,
         onSaved: onSaved,
         inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
         onChanged: (String? value) {
@@ -154,9 +165,7 @@ class _AddMeasurementDialogeState extends State<AddMeasurementDialoge> {
       appBar: AppBar(
         forceMaterialTransparency: true,
         leading: IconButton(
-            onPressed: () {
-              Navigator.of(context).pop(null);
-            },
+            onPressed: () => Navigator.of(context).pop(null),
             icon: const Icon(Icons.close)
         ),
         actions: [
@@ -183,6 +192,7 @@ class _AddMeasurementDialogeState extends State<AddMeasurementDialoge> {
               mainAxisSize: MainAxisSize.min,
               children: [
                 buildValueInput(localizations,
+                  focusNode: firstFocusNode,
                   hintText: localizations.sysLong,
                   initialValue: widget.initialRecord?.systolic,
                   onSaved: (value) => setState(() => systolic = int.tryParse(value ?? '')),
lib/screens/home.dart
@@ -79,7 +79,8 @@ class AppHome extends StatelessWidget {
                       autofocus: true,
                       onPressed: () async {
                         final value = await showAddMeasurementDialoge(context, settings);
-                        // TODO: save
+                        // TODO: save value
+                        // TODO: use new dialog when editing measurements
                       },
                       child: const Icon(Icons.add,),
                     ),