From a4ea7719851c075b5961ef59e5bf1d1f697ff340 Mon Sep 17 00:00:00 2001 From: Sarthak Date: Wed, 18 Mar 2026 22:55:37 +0530 Subject: [PATCH] feat(measurements): remove date restriction to allow multiple entries per day --- lib/widgets/measurements/forms.dart | 161 +--------------------------- 1 file changed, 1 insertion(+), 160 deletions(-) diff --git a/lib/widgets/measurements/forms.dart b/lib/widgets/measurements/forms.dart index d315d5f36..621253f8c 100644 --- a/lib/widgets/measurements/forms.dart +++ b/lib/widgets/measurements/forms.dart @@ -158,163 +158,4 @@ class MeasurementEntryForm extends StatelessWidget { } _valueController.text = ''; - _notesController.text = _entryData['notes']!; - } - - @override - Widget build(BuildContext context) { - final dateFormat = DateFormat.yMd(Localizations.localeOf(context).languageCode); - - final measurementProvider = Provider.of(context, listen: false); - final measurementCategory = measurementProvider.categories.firstWhere( - (category) => category.id == _categoryId, - ); - - if (_dateController.text.isEmpty) { - _dateController.text = dateFormat.format(_entryData['date']); - } - - final numberFormat = NumberFormat.decimalPattern(Localizations.localeOf(context).toString()); - - // If the value is not empty, format it - if (_valueController.text.isEmpty && _entryData['value'] != null && _entryData['value'] != '') { - _valueController.text = numberFormat.format(_entryData['value']); - } - - return Form( - key: _form, - child: Column( - children: [ - TextFormField( - decoration: InputDecoration( - labelText: AppLocalizations.of(context).date, - suffixIcon: const Icon( - Icons.calendar_today, - key: Key('calendarIcon'), - ), - ), - readOnly: true, - // Hide text cursor - controller: _dateController, - onTap: () async { - // Stop keyboard from appearing - FocusScope.of(context).requestFocus(FocusNode()); - - // Show Date Picker Here - final pickedDate = await showDatePicker( - context: context, - initialDate: _entryData['date'], - firstDate: DateTime(DateTime.now().year - 10), - lastDate: DateTime.now(), - - // TODO(x): we need to filter out dates that already have an entry - selectableDayPredicate: (day) { - // Always allow the current initial date - if (day == _entryData['date']) { - return true; - } - return true; - }, - ); - - _dateController.text = pickedDate == null ? '' : dateFormat.format(pickedDate); - }, - onSaved: (newValue) { - _entryData['date'] = dateFormat.parse(newValue!); - }, - validator: (value) { - if (value!.isEmpty) { - return AppLocalizations.of(context).enterValue; - } - return null; - }, - ), - // Value - TextFormField( - decoration: InputDecoration( - labelText: AppLocalizations.of(context).value, - suffixIcon: Text(measurementCategory.unit), - suffixIconConstraints: const BoxConstraints(minWidth: 0, minHeight: 0), - ), - controller: _valueController, - keyboardType: textInputTypeDecimal, - validator: (value) { - if (value!.isEmpty) { - return AppLocalizations.of(context).enterValue; - } - try { - numberFormat.parse(value); - } catch (error) { - return AppLocalizations.of(context).enterValidNumber; - } - return null; - }, - onSaved: (newValue) { - _entryData['value'] = numberFormat.parse(newValue!); - }, - ), - // Value - TextFormField( - decoration: InputDecoration(labelText: AppLocalizations.of(context).notes), - controller: _notesController, - onSaved: (newValue) { - _entryData['notes'] = newValue; - }, - validator: (value) { - const minLength = 0; - const maxLength = 100; - if (value!.isNotEmpty && (value.length < minLength || value.length > maxLength)) { - return AppLocalizations.of(context).enterCharacters( - minLength.toString(), - maxLength.toString(), - ); - } - return null; - }, - ), - - ElevatedButton( - child: Text(AppLocalizations.of(context).save), - onPressed: () async { - // Validate and save the current values to the weightEntry - final isValid = _form.currentState!.validate(); - if (!isValid) { - return; - } - _form.currentState!.save(); - - // Save the entry on the server - _entryData['id'] == null - ? await Provider.of( - context, - listen: false, - ).addEntry( - MeasurementEntry( - id: _entryData['id'], - category: _entryData['category'], - date: _entryData['date'], - value: _entryData['value'], - notes: _entryData['notes'], - ), - ) - : await Provider.of( - context, - listen: false, - ).editEntry( - _entryData['id'], - _entryData['category'], - _entryData['value'], - _entryData['notes'], - _entryData['date'], - ); - - if (context.mounted) { - Navigator.of(context).pop(); - } - }, - ), - ], - ), - ); - } -} + _notesCon \ No newline at end of file