• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wger-project / flutter / 30854254088

03 Aug 2026 09:21PM UTC coverage: 40.895% (-15.0%) from 55.93%
30854254088

Pull #1260

github

web-flow
Merge d93794de5 into e3affdd4f
Pull Request #1260: WIP: health sync

9980 of 24404 relevant lines covered (40.89%)

1.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.54
/lib/core/form_validators.dart
1
/*
2
 * This file is part of wger Workout Manager <https://github.com/wger-project>.
3
 * Copyright (c)  2026 wger Team
4
 *
5
 * wger Workout Manager is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

19
import 'package:flutter/material.dart';
20
import 'package:intl/intl.dart';
21
import 'package:wger/l10n/generated/app_localizations.dart';
22

23
/// Validates an optional decimal text field.
24
///
25
/// Empty input is allowed and returns `null`. Non-empty input must be
26
/// parseable by [numberFormat]; otherwise an `enterValidNumber` error
27
/// message is returned. When [max] is set, the value must also be within
28
/// `0..max` (inclusive).
29
String? validateOptionalDecimal(
1✔
30
  String? text,
31
  NumberFormat numberFormat,
32
  BuildContext context, {
33
  num? max,
34
}) {
35
  final trimmed = (text ?? '').trim();
1✔
36
  if (trimmed.isEmpty) {
1✔
37
    return null;
38
  }
39
  final parsed = numberFormat.tryParse(trimmed);
1✔
40
  if (parsed == null) {
41
    return AppLocalizations.of(context).enterValidNumber;
×
42
  }
43
  if (max != null && (parsed < 0 || parsed > max)) {
2✔
44
    return AppLocalizations.of(context).formMinMaxValues(0, max.toInt());
3✔
45
  }
46
  return null;
47
}
48

49
/// Validates an optional whole-number field. Empty input is allowed and returns
50
/// `null`; otherwise the value must be an integer within [min]..[max] inclusive.
51
String? validateOptionalIntegerInRange(
1✔
52
  String? value,
53
  int min,
54
  int max,
55
  AppLocalizations i18n,
56
) {
57
  if (value == null || value.isEmpty) {
1✔
58
    return null;
59
  }
60
  final parsed = int.tryParse(value);
×
61
  if (parsed == null) {
62
    return i18n.enterValidNumber;
×
63
  }
64
  if (parsed < min || parsed > max) {
×
65
    return i18n.formMinMaxValues(min, max);
×
66
  }
67
  return null;
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc