Commit 5746d18

derdilla <derdilla06@gmail.com>
2023-06-04 11:42:00
make add measurement screen scrollable
1 parent daaa4e4
Changed files (1)
lib/screens/add_measurement.dart
@@ -54,206 +54,208 @@ class _AddMeasurementPageState extends State<AddMeasurementPage> {
       body: Center(
         child: Form(
           key: _formKey,
-          child: Container(
-            padding: const EdgeInsets.all(60.0),
-            child: Column(
-              mainAxisAlignment: MainAxisAlignment.center,
-              crossAxisAlignment: CrossAxisAlignment.center,
-              children: [
-                Consumer<Settings>(
-                    builder: (context, settings, child) {
-                      final formatter = DateFormat(settings.dateFormatString);
-                      if(settings.allowManualTimeInput) {
-                        return GestureDetector(
-                          onTap: () async {
-                            var selectedTime = await showDateTimePicker(
-                              context: context,
-                              firstDate: DateTime.fromMillisecondsSinceEpoch(0),
-                              lastDate: DateTime.now().copyWith(second: DateTime.now().second+1)
-                            );
-                            if (selectedTime != null) {
-                              setState(() {
-                              _time = selectedTime;
-                            });
-                            }
-                          },
-                          child: Column(
-                            children: [
-                              Row(
-                                children: [
-                                  Text(formatter.format(_time)),
-                                  const Spacer(),
-                                  const Icon(Icons.edit)
-                                ],
-                              ),
-                              const SizedBox(height: 3,),
-                              Divider(
-                                color: Theme.of(context).disabledColor,
-                                thickness: 1,
-                              )
-                            ],
-                          ),
-                        );
-                      } else {
-                        return const SizedBox.shrink();
-                      }
-                    }
-                ),
-                Consumer<Settings>(
-                  builder: (context, settings, child) {
-                    return TextFormField(
-                      key: const Key('txtSys'),
-                      initialValue: widget.isEdit ? _systolic.toString() : '',
-                      decoration: const InputDecoration(
-                          hintText: 'systolic'
-                      ),
-                      keyboardType: TextInputType.number,
-                      inputFormatters: <TextInputFormatter>[
-                        FilteringTextInputFormatter.digitsOnly
-                      ],
-                      focusNode: _sysFocusNode,
-                      onChanged: (String? value) {
-                        // to next field
-                        if ( value != null && value.isNotEmpty &&
-                            (int.tryParse(value) ?? -1) > 40) {
-                          FocusScope.of(context).nextFocus();
-                        }
-                      },
-                      validator: (String? value) {
-                        if (value == null || value.isEmpty
-                            || (int.tryParse(value) == null)) {
-                          return 'Please enter a Number';
-                        } else if (settings.validateInputs && (int.tryParse(value) ?? -1) <= 30) {
-                          return 'Number < 30? Turn off validation in settings!';
-                        } else if (settings.validateInputs && (int.tryParse(value) ?? 1000) >= 400) { // exceeding this value is unlikely: https://pubmed.ncbi.nlm.nih.gov/7741618/
-                          return 'Unrealistic value? Turn off validation in settings!';
-                        } else {
-                          _systolic = int.tryParse(value) ?? -1;
-                        }
-                        return null;
-                      },
-                    );
-                  }
-                ),
-                Consumer<Settings>(
-                  builder: (context, settings, child) {
-                    return TextFormField(
-                      key: const Key('txtDia'),
-                      initialValue: widget.isEdit ? _diastolic.toString() : '',
-                      decoration: const InputDecoration(
-                          hintText: 'diastolic'
-                      ),
-                      keyboardType: TextInputType.number,
-                      inputFormatters: <TextInputFormatter>[
-                        FilteringTextInputFormatter.digitsOnly
-                      ],
-                      onChanged: (String? value) {
-                        // to next field
-                        if ( value != null && value.isNotEmpty &&
-                            (int.tryParse(value) ?? -1) > 40) {
-                          FocusScope.of(context).nextFocus();
-                        }
-                      },
-                      validator: (String? value) {
-                        if (value == null || value.isEmpty
-                            || (int.tryParse(value) == null)) {
-                          return 'Please enter a Number';
-                        } else if (settings.validateInputs && (int.tryParse(value) ?? -1) <= 30) {
-                          return 'Number < 30? Turn off validation in settings!';
-                        } else if (settings.validateInputs && (int.tryParse(value) ?? 1000) >= 400) { // exceeding this value is unlikely: https://pubmed.ncbi.nlm.nih.gov/7741618/
-                          return 'Unrealistic value? Turn off validation in settings!';
-                        } else {
-                          _diastolic = int.tryParse(value) ?? -1;
-                        }
-                        return null;
-                      },
-                    );
-                  }
-                ),
-                Consumer<Settings>(
-                  builder: (context, settings, child) {
-                    return TextFormField(
-                      key: const Key('txtPul'),
-                      initialValue: widget.isEdit ? _pulse.toString() : '',
-                      decoration: const InputDecoration(
-                          hintText: 'pulse'
-                      ),
-                      keyboardType: TextInputType.number,
-                      inputFormatters: <TextInputFormatter>[
-                        FilteringTextInputFormatter.digitsOnly
-                      ],
-                      onChanged: (String? value) {
-                        // to next field
-                        if ( value != null && value.isNotEmpty &&
-                            (int.tryParse(value) ?? -1) > 35) {
-                          FocusScope.of(context).nextFocus();
-                        }
-                      },
-                      validator: (String? value) {
-                        if (value == null || value.isEmpty
-                            || (int.tryParse(value) == null)) {
-                          return 'Please enter a Number';
-                        } else if (settings.validateInputs && (int.tryParse(value) ?? -1) <= 30) {
-                          return 'Number < 30? Turn off validation in settings!';
-                        } else if (settings.validateInputs && (int.tryParse(value) ?? 1000) >= 600) { // exceeding this value is unlikely: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3273956/
-                          return 'Unrealistic value? Turn off validation in settings!';
+          child: SingleChildScrollView(
+            child: Container(
+              padding: const EdgeInsets.all(60.0),
+              child: Column(
+                mainAxisAlignment: MainAxisAlignment.center,
+                crossAxisAlignment: CrossAxisAlignment.center,
+                children: [
+                  Consumer<Settings>(
+                      builder: (context, settings, child) {
+                        final formatter = DateFormat(settings.dateFormatString);
+                        if(settings.allowManualTimeInput) {
+                          return GestureDetector(
+                            onTap: () async {
+                              var selectedTime = await showDateTimePicker(
+                                context: context,
+                                firstDate: DateTime.fromMillisecondsSinceEpoch(0),
+                                lastDate: DateTime.now().copyWith(second: DateTime.now().second+1)
+                              );
+                              if (selectedTime != null) {
+                                setState(() {
+                                _time = selectedTime;
+                              });
+                              }
+                            },
+                            child: Column(
+                              children: [
+                                Row(
+                                  children: [
+                                    Text(formatter.format(_time)),
+                                    const Spacer(),
+                                    const Icon(Icons.edit)
+                                  ],
+                                ),
+                                const SizedBox(height: 3,),
+                                Divider(
+                                  color: Theme.of(context).disabledColor,
+                                  thickness: 1,
+                                )
+                              ],
+                            ),
+                          );
                         } else {
-                          _pulse = int.tryParse(value) ?? -1;
+                          return const SizedBox.shrink();
                         }
-                        return null;
-                      },
-                    );
-                  }
-                ),
-                TextFormField(
-                  initialValue: widget.isEdit ? _note.toString() : '',
-                  decoration: const InputDecoration(
-                      hintText: 'note (optional)'
+                      }
                   ),
-                  validator: (String? value) {
-                    _note = value ?? "";
-                    return null;
-                  },
-                ),
-                const SizedBox(
-                  height: 24,
-                ),
-                Row(
-                  children: [
-                    ElevatedButton(
-                      key: const Key('btnCancel'),
-                      onPressed: () {
-                        if (widget.isEdit) {
-                          Provider.of<BloodPressureModel>(context, listen: false).add(
-                              BloodPressureRecord(widget.initTime ?? DateTime.now(), widget.initSys, widget.initDia, widget.initPul, widget.initNote)
-                          );
-                        }
-                        Navigator.of(context).pop();
-                      },
-                      style: ElevatedButton.styleFrom(
-                          backgroundColor: Theme.of(context).unselectedWidgetColor
-                      ),
-                      child: const Text('CANCEL')
+                  Consumer<Settings>(
+                    builder: (context, settings, child) {
+                      return TextFormField(
+                        key: const Key('txtSys'),
+                        initialValue: widget.isEdit ? _systolic.toString() : '',
+                        decoration: const InputDecoration(
+                            hintText: 'systolic'
+                        ),
+                        keyboardType: TextInputType.number,
+                        inputFormatters: <TextInputFormatter>[
+                          FilteringTextInputFormatter.digitsOnly
+                        ],
+                        focusNode: _sysFocusNode,
+                        onChanged: (String? value) {
+                          // to next field
+                          if ( value != null && value.isNotEmpty &&
+                              (int.tryParse(value) ?? -1) > 40) {
+                            FocusScope.of(context).nextFocus();
+                          }
+                        },
+                        validator: (String? value) {
+                          if (value == null || value.isEmpty
+                              || (int.tryParse(value) == null)) {
+                            return 'Please enter a Number';
+                          } else if (settings.validateInputs && (int.tryParse(value) ?? -1) <= 30) {
+                            return 'Number < 30? Turn off validation in settings!';
+                          } else if (settings.validateInputs && (int.tryParse(value) ?? 1000) >= 400) { // exceeding this value is unlikely: https://pubmed.ncbi.nlm.nih.gov/7741618/
+                            return 'Unrealistic value? Turn off validation in settings!';
+                          } else {
+                            _systolic = int.tryParse(value) ?? -1;
+                          }
+                          return null;
+                        },
+                      );
+                    }
+                  ),
+                  Consumer<Settings>(
+                    builder: (context, settings, child) {
+                      return TextFormField(
+                        key: const Key('txtDia'),
+                        initialValue: widget.isEdit ? _diastolic.toString() : '',
+                        decoration: const InputDecoration(
+                            hintText: 'diastolic'
+                        ),
+                        keyboardType: TextInputType.number,
+                        inputFormatters: <TextInputFormatter>[
+                          FilteringTextInputFormatter.digitsOnly
+                        ],
+                        onChanged: (String? value) {
+                          // to next field
+                          if ( value != null && value.isNotEmpty &&
+                              (int.tryParse(value) ?? -1) > 40) {
+                            FocusScope.of(context).nextFocus();
+                          }
+                        },
+                        validator: (String? value) {
+                          if (value == null || value.isEmpty
+                              || (int.tryParse(value) == null)) {
+                            return 'Please enter a Number';
+                          } else if (settings.validateInputs && (int.tryParse(value) ?? -1) <= 30) {
+                            return 'Number < 30? Turn off validation in settings!';
+                          } else if (settings.validateInputs && (int.tryParse(value) ?? 1000) >= 400) { // exceeding this value is unlikely: https://pubmed.ncbi.nlm.nih.gov/7741618/
+                            return 'Unrealistic value? Turn off validation in settings!';
+                          } else {
+                            _diastolic = int.tryParse(value) ?? -1;
+                          }
+                          return null;
+                        },
+                      );
+                    }
+                  ),
+                  Consumer<Settings>(
+                    builder: (context, settings, child) {
+                      return TextFormField(
+                        key: const Key('txtPul'),
+                        initialValue: widget.isEdit ? _pulse.toString() : '',
+                        decoration: const InputDecoration(
+                            hintText: 'pulse'
+                        ),
+                        keyboardType: TextInputType.number,
+                        inputFormatters: <TextInputFormatter>[
+                          FilteringTextInputFormatter.digitsOnly
+                        ],
+                        onChanged: (String? value) {
+                          // to next field
+                          if ( value != null && value.isNotEmpty &&
+                              (int.tryParse(value) ?? -1) > 35) {
+                            FocusScope.of(context).nextFocus();
+                          }
+                        },
+                        validator: (String? value) {
+                          if (value == null || value.isEmpty
+                              || (int.tryParse(value) == null)) {
+                            return 'Please enter a Number';
+                          } else if (settings.validateInputs && (int.tryParse(value) ?? -1) <= 30) {
+                            return 'Number < 30? Turn off validation in settings!';
+                          } else if (settings.validateInputs && (int.tryParse(value) ?? 1000) >= 600) { // exceeding this value is unlikely: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3273956/
+                            return 'Unrealistic value? Turn off validation in settings!';
+                          } else {
+                            _pulse = int.tryParse(value) ?? -1;
+                          }
+                          return null;
+                        },
+                      );
+                    }
+                  ),
+                  TextFormField(
+                    initialValue: widget.isEdit ? _note.toString() : '',
+                    decoration: const InputDecoration(
+                        hintText: 'note (optional)'
                     ),
-                    const Spacer(),
-                    ElevatedButton(
-                      key: const Key('btnSave'),
-                      onPressed: () {
-                        if (_formKey.currentState!.validate()) {
-                          Provider.of<BloodPressureModel>(context, listen: false).add(
-                              BloodPressureRecord(_time, _systolic, _diastolic, _pulse, _note)
-                          );
+                    validator: (String? value) {
+                      _note = value ?? "";
+                      return null;
+                    },
+                  ),
+                  const SizedBox(
+                    height: 24,
+                  ),
+                  Row(
+                    children: [
+                      ElevatedButton(
+                        key: const Key('btnCancel'),
+                        onPressed: () {
+                          if (widget.isEdit) {
+                            Provider.of<BloodPressureModel>(context, listen: false).add(
+                                BloodPressureRecord(widget.initTime ?? DateTime.now(), widget.initSys, widget.initDia, widget.initPul, widget.initNote)
+                            );
+                          }
                           Navigator.of(context).pop();
-                        }
-                      },
-                      style: ElevatedButton.styleFrom(
-                          backgroundColor: Theme.of(context).primaryColor
+                        },
+                        style: ElevatedButton.styleFrom(
+                            backgroundColor: Theme.of(context).unselectedWidgetColor
+                        ),
+                        child: const Text('CANCEL')
                       ),
-                      child: const Text('SAVE')
-                    )
-                  ],
-                )
-              ],
+                      const Spacer(),
+                      ElevatedButton(
+                        key: const Key('btnSave'),
+                        onPressed: () {
+                          if (_formKey.currentState!.validate()) {
+                            Provider.of<BloodPressureModel>(context, listen: false).add(
+                                BloodPressureRecord(_time, _systolic, _diastolic, _pulse, _note)
+                            );
+                            Navigator.of(context).pop();
+                          }
+                        },
+                        style: ElevatedButton.styleFrom(
+                            backgroundColor: Theme.of(context).primaryColor
+                        ),
+                        child: const Text('SAVE')
+                      )
+                    ],
+                  )
+                ],
+              ),
             ),
           ),
         ),