• 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

21.43
/lib/core/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:wger/l10n/generated/app_localizations.dart';
20

21
/// Validates that [end], when set, is not before [start]. Returns a localized
22
/// error message on failure, or null when the range is valid (including when
23
/// [end] is null).
24
String? validateDateRange(DateTime start, DateTime? end, AppLocalizations i18n) {
3✔
25
  if (end != null && end.isBefore(start)) {
2✔
26
    return i18n.endBeforeStart;
1✔
27
  }
28
  return null;
29
}
30

31
String? validateUrl(String? value, AppLocalizations i18n, {bool required = true}) {
×
32
  // Required?
33
  if (required && (value == null || value.trim().isEmpty)) {
×
34
    return i18n.enterValue;
×
35
  }
36

37
  if (!required && (value == null || value.trim().isEmpty)) {
×
38
    return null;
39
  }
40
  value = value!.trim();
×
41

42
  if (!value.startsWith('http://') && !value.startsWith('https://')) {
×
43
    return i18n.invalidUrl;
×
44
  }
45

46
  // Try to parse as URI. The earlier startsWith check guarantees a scheme
47
  // and the `//` authority delimiter, but `Uri.parse('http://')` still
48
  // succeeds with an empty host which we reject explicitly
49
  try {
50
    final uri = Uri.parse(value);
×
51
    if (uri.host.isEmpty) {
×
52
      return i18n.invalidUrl;
×
53
    }
54
  } catch (e) {
55
    return i18n.invalidUrl;
×
56
  }
57

58
  return null;
59
}
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