mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-28 17:08:29 +01:00
Fixed i18n
and added a max allowed weight as well (but this should probably be done everywhere)
This commit is contained in:
@@ -231,6 +231,7 @@ class IngredientFormState extends State<IngredientForm> {
|
||||
final dateFormat = DateFormat.yMd(languageCode);
|
||||
final timeFormat = DateFormat.Hm(languageCode);
|
||||
final dateTimeFormat = DateFormat.yMd(languageCode).add_Hm();
|
||||
final i18n = AppLocalizations.of(context);
|
||||
|
||||
if (_dateController.text.isEmpty) {
|
||||
_dateController.text = dateFormat.format(DateTime.now());
|
||||
@@ -240,7 +241,7 @@ class IngredientFormState extends State<IngredientForm> {
|
||||
_timeController.text = timeFormat.format(DateTime.now());
|
||||
}
|
||||
|
||||
final String unit = AppLocalizations.of(context).g;
|
||||
final String unit = i18n.g;
|
||||
final queryLower = _searchQuery.toLowerCase();
|
||||
final suggestions = widget.recent
|
||||
.where((e) => e.ingredient.name.toLowerCase().contains(queryLower))
|
||||
@@ -268,9 +269,7 @@ class IngredientFormState extends State<IngredientForm> {
|
||||
child: TextFormField(
|
||||
key: const Key('field-weight'),
|
||||
// needed ?
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).weight,
|
||||
),
|
||||
decoration: InputDecoration(labelText: i18n.weight),
|
||||
controller: _amountController,
|
||||
keyboardType: textInputTypeDecimal,
|
||||
onChanged: (value) {
|
||||
@@ -287,15 +286,15 @@ class IngredientFormState extends State<IngredientForm> {
|
||||
validator: (value) {
|
||||
final text = value?.trim() ?? '';
|
||||
if (text.isEmpty) {
|
||||
return 'Please enter a weight.';
|
||||
return i18n.enterValue;
|
||||
}
|
||||
final parsed = double.tryParse(text);
|
||||
if (parsed == null) {
|
||||
return AppLocalizations.of(context).enterValidNumber;
|
||||
return i18n.enterValidNumber;
|
||||
}
|
||||
// Must be at least 1
|
||||
if (parsed < 1) {
|
||||
return 'Weight must be at least 1.';
|
||||
|
||||
if (parsed < 1 || parsed > 1000) {
|
||||
return i18n.formMinMaxValues(1, 1000);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@@ -307,7 +306,7 @@ class IngredientFormState extends State<IngredientForm> {
|
||||
readOnly: true,
|
||||
// Stop keyboard from appearing
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).date,
|
||||
labelText: i18n.date,
|
||||
// suffixIcon: const Icon(Icons.calendar_today),
|
||||
),
|
||||
enableInteractiveSelection: false,
|
||||
@@ -335,7 +334,7 @@ class IngredientFormState extends State<IngredientForm> {
|
||||
child: TextFormField(
|
||||
key: const Key('field-time'),
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).time,
|
||||
labelText: i18n.time,
|
||||
//suffixIcon: const Icon(Icons.punch_clock)
|
||||
),
|
||||
controller: _timeController,
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (c) 2026 - 2026 wger Team
|
||||
*
|
||||
* wger Workout Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -186,7 +204,7 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Please enter a valid number'), findsOneWidget);
|
||||
expect(find.text('Please enter a value'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('add correct weight type', (WidgetTester tester) async {
|
||||
@@ -253,8 +271,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Please select an ingredient'), findsOneWidget);
|
||||
|
||||
expect(find.text('Please enter a valid number'), findsOneWidget);
|
||||
expect(find.text('Please enter a value'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('save ingredient without weight', (WidgetTester tester) async {
|
||||
@@ -273,25 +290,7 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Please enter a valid number'), findsOneWidget);
|
||||
});
|
||||
|
||||
//TODO: isn't this test just a duplicate of the above one? can be removed?
|
||||
testWidgets('save ingredient with incorrect weight input type', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true));
|
||||
|
||||
await tester.tap(find.byKey(const Key('scan-button')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('ingredient-scan-result-dialog')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('ingredient-scan-result-dialog-confirm-button')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Please enter a valid number'), findsOneWidget);
|
||||
expect(find.text('Please enter a value'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
|
||||
Reference in New Issue
Block a user