fix: food name field validation
Pull Request: Meal Name Validation
Description
This PR fixes the “Meal Name” field validation in OpenNutriTracker, preventing inputs made up solely of numbers or special characters, and ensuring at least one alphabetical character is present.
What Was Done
-
Input Validation
Created and testedFoodNameValidator.isValid, which enforces at least one letter in the meal name. -
Form Integration
Wrapped name and related fields in aFormusing aGlobalKey<FormState>and added avalidatorto the meal nameTextFormField. -
Submission Blocking
Updated_onSavePressedto callformKey.currentState!.validate()before proceeding, preventing invalid submissions. -
Test Coverage
- Unit Tests rejecting number‑only or symbol‑only names and accepting letter‑containing names.
Linked Issues
Bug: App allows adding a meal with only numbers and special characters in the name #211
TDD Cycles
-
Red
- Wrote failing unit tests for the new validation scenarios.
-
Green‑1
- Introduced a stub (
return false) and fixed imports so tests compile (but still fail).
- Introduced a stub (
-
Green‑2
- Implemented real logic with
RegExp(r'[A-Za-z]'), making all tests pass.
- Implemented real logic with
-
Refactor & Integrate
- Applied the validated logic in the form and ensured submission is blocked on error.
Outcome
- All tests pass successfully.
- The UI displays “The name must contain at least one letter” and prevents saving until corrected.