mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Correctly parse the localized weight values in the form
This commit is contained in:
@@ -22,6 +22,7 @@ import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/helpers/json.dart';
|
||||
import 'package:wger/helpers/misc.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/models/body_weight/weight_entry.dart';
|
||||
import 'package:wger/providers/body_weight.dart';
|
||||
@@ -35,7 +36,7 @@ class WeightForm extends StatelessWidget {
|
||||
|
||||
WeightForm([WeightEntry? weightEntry]) {
|
||||
_weightEntry = weightEntry ?? WeightEntry(date: DateTime.now());
|
||||
weightController.text = _weightEntry.weight == 0 ? '' : _weightEntry.weight.toString();
|
||||
weightController.text = '';
|
||||
dateController.text = dateToYYYYMMDD(_weightEntry.date)!;
|
||||
}
|
||||
|
||||
@@ -43,6 +44,10 @@ class WeightForm extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final numberFormat = NumberFormat.decimalPattern(Localizations.localeOf(context).toString());
|
||||
|
||||
if (weightController.text.isEmpty && _weightEntry.weight != 0) {
|
||||
weightController.text = numberFormat.format(_weightEntry.weight);
|
||||
}
|
||||
|
||||
return Form(
|
||||
key: _form,
|
||||
child: Column(
|
||||
@@ -69,7 +74,7 @@ class WeightForm extends StatelessWidget {
|
||||
lastDate: DateTime.now(),
|
||||
selectableDayPredicate: (day) {
|
||||
// Always allow the current initial date
|
||||
if (day == _weightEntry.date) {
|
||||
if (day.isSameDayAs(_weightEntry.date)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -101,8 +106,8 @@ class WeightForm extends StatelessWidget {
|
||||
icon: const FaIcon(FontAwesomeIcons.circleMinus),
|
||||
onPressed: () {
|
||||
try {
|
||||
final num newValue = num.parse(weightController.text) - 1;
|
||||
weightController.text = newValue.toString();
|
||||
final newValue = numberFormat.parse(weightController.text) - 1;
|
||||
weightController.text = numberFormat.format(newValue);
|
||||
} on FormatException {}
|
||||
},
|
||||
),
|
||||
@@ -111,8 +116,8 @@ class WeightForm extends StatelessWidget {
|
||||
icon: const FaIcon(FontAwesomeIcons.minus),
|
||||
onPressed: () {
|
||||
try {
|
||||
final num newValue = num.parse(weightController.text) - 0.1;
|
||||
weightController.text = newValue.toStringAsFixed(1);
|
||||
final newValue = numberFormat.parse(weightController.text) - 0.1;
|
||||
weightController.text = numberFormat.format(newValue);
|
||||
} on FormatException {}
|
||||
},
|
||||
),
|
||||
@@ -126,8 +131,8 @@ class WeightForm extends StatelessWidget {
|
||||
icon: const FaIcon(FontAwesomeIcons.plus),
|
||||
onPressed: () {
|
||||
try {
|
||||
final num newValue = num.parse(weightController.text) + 0.1;
|
||||
weightController.text = newValue.toStringAsFixed(1);
|
||||
final newValue = numberFormat.parse(weightController.text) + 0.1;
|
||||
weightController.text = numberFormat.format(newValue);
|
||||
} on FormatException {}
|
||||
},
|
||||
),
|
||||
@@ -136,8 +141,8 @@ class WeightForm extends StatelessWidget {
|
||||
icon: const FaIcon(FontAwesomeIcons.circlePlus),
|
||||
onPressed: () {
|
||||
try {
|
||||
final num newValue = num.parse(weightController.text) + 1;
|
||||
weightController.text = newValue.toString();
|
||||
final newValue = numberFormat.parse(weightController.text) + 1;
|
||||
weightController.text = numberFormat.format(newValue);
|
||||
} on FormatException {}
|
||||
},
|
||||
),
|
||||
|
||||
@@ -56,7 +56,7 @@ void main() {
|
||||
expect(find.text('79.9'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('quickPlusSmall')));
|
||||
expect(find.text('80.0'), findsOneWidget);
|
||||
expect(find.text('80'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Entering garbage doesn't break the quick-change", (WidgetTester tester) async {
|
||||
|
||||
Reference in New Issue
Block a user