Skip to content

Commit 40daf37

Browse files
committed
Format all
1 parent 2d8f2ce commit 40daf37

File tree

9 files changed

+520
-488
lines changed

9 files changed

+520
-488
lines changed

example/analysis_options.yaml

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
1-
# This file configures the analyzer, which statically analyzes Dart code to
2-
# check for errors, warnings, and lints.
3-
#
4-
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5-
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6-
# invoked from the command line by running `flutter analyze`.
7-
8-
# The following line activates a set of recommended lints for Flutter apps,
9-
# packages, and plugins designed to encourage good coding practices.
101
include: package:flutter_lints/flutter.yaml
112

12-
linter:
13-
# The lint rules applied to this project can be customized in the
14-
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15-
# included above or to enable additional rules. A list of all available lints
16-
# and their documentation is published at
17-
# https://dart-lang.github.io/linter/lints/index.html.
18-
#
19-
# Instead of disabling a lint rule for the entire project in the
20-
# section below, it can also be suppressed for a single line of code
21-
# or a specific dart file by using the `// ignore: name_of_lint` and
22-
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
23-
# producing the lint.
24-
rules:
25-
# avoid_print: false # Uncomment to disable the `avoid_print` rule
26-
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27-
28-
# Additional information about this file can be found at
29-
# https://dart.dev/guides/language/analysis-options
3+
analyzer:
4+
exclude:
5+
- lib/localization/intl/**

example/lib/home_page.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class HomePageState extends State<HomePage> {
1414
return Scaffold(
1515
appBar: AppBar(title: const Text('Form Builder Validators')),
1616
body: Padding(
17-
padding: const EdgeInsets.all(8.0),
17+
padding: const EdgeInsets.all(8),
1818
child: Column(
1919
children: <Widget>[
2020
TextFormField(
@@ -34,7 +34,8 @@ class HomePageState extends State<HomePage> {
3434

3535
/// Ensures the value entered is numeric - with custom error message
3636
FormBuilderValidators.numeric(
37-
errorText: 'La edad debe ser numérica.'),
37+
errorText: 'La edad debe ser numérica.',
38+
),
3839

3940
/// Sets a maximum value of 70
4041
FormBuilderValidators.max(70),

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import 'package:example/override_form_builder_localizations_en.dart';
21
import 'package:flutter/material.dart';
32
import 'package:flutter_localizations/flutter_localizations.dart';
43
import 'package:form_builder_validators/form_builder_validators.dart';
54

65
import 'home_page.dart';
6+
import 'override_form_builder_localizations_en.dart';
77

88
void main() {
99
runApp(const MyApp());

lib/form_builder_validators.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
library form_builder_validators;
2-
31
export 'localization/intl/messages.dart';
42
export 'localization/intl/messages_ar.dart';
53
export 'localization/intl/messages_bn.dart';

lib/localization/l10n.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class FormBuilderLocalizations {
1313

1414
static FormBuilderLocalizationsImpl of(BuildContext context) {
1515
return Localizations.of<FormBuilderLocalizationsImpl>(
16-
context, FormBuilderLocalizationsImpl) ??
16+
context,
17+
FormBuilderLocalizationsImpl,
18+
) ??
1719
_default;
1820
}
1921

lib/src/form_builder_validators.dart

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'package:form_builder_validators/form_builder_validators.dart';
2+
import '../form_builder_validators.dart';
33

44
import 'utils/validators.dart';
55

@@ -9,9 +9,10 @@ class FormBuilderValidators {
99
/// Each validator is run against the [FormField] value and if any returns a
1010
/// non-null result validation fails, otherwise, validation passes
1111
static FormFieldValidator<T> compose<T>(
12-
List<FormFieldValidator<T>> validators) {
12+
List<FormFieldValidator<T>> validators,
13+
) {
1314
return (valueCandidate) {
14-
for (var validator in validators) {
15+
for (final validator in validators) {
1516
final validatorResult = validator.call(valueCandidate);
1617
if (validatorResult != null) {
1718
return validatorResult;
@@ -112,9 +113,11 @@ class FormBuilderValidators {
112113
}) {
113114
assert(minLength > 0);
114115
return (T? valueCandidate) {
115-
assert(valueCandidate is String ||
116-
valueCandidate is Iterable ||
117-
valueCandidate == null);
116+
assert(
117+
valueCandidate is String ||
118+
valueCandidate is Iterable ||
119+
valueCandidate == null,
120+
);
118121
var valueLength = 0;
119122
if (valueCandidate is String) valueLength = valueCandidate.length;
120123
if (valueCandidate is Iterable) valueLength = valueCandidate.length;
@@ -133,9 +136,11 @@ class FormBuilderValidators {
133136
}) {
134137
assert(maxLength > 0);
135138
return (T? valueCandidate) {
136-
assert(valueCandidate is String ||
137-
valueCandidate is Iterable ||
138-
valueCandidate == null);
139+
assert(
140+
valueCandidate is String ||
141+
valueCandidate is Iterable ||
142+
valueCandidate == null,
143+
);
139144
int valueLength = 0;
140145
if (valueCandidate is String) valueLength = valueCandidate.length;
141146
if (valueCandidate is Iterable) valueLength = valueCandidate.length;
@@ -155,10 +160,12 @@ class FormBuilderValidators {
155160
}) {
156161
assert(length > 0);
157162
return (T? valueCandidate) {
158-
assert(valueCandidate is String ||
159-
valueCandidate is Iterable ||
160-
valueCandidate is int ||
161-
valueCandidate == null);
163+
assert(
164+
valueCandidate is String ||
165+
valueCandidate is Iterable ||
166+
valueCandidate is int ||
167+
valueCandidate == null,
168+
);
162169
int valueLength = 0;
163170

164171
if (valueCandidate is int) valueLength = valueCandidate.toString().length;
@@ -202,7 +209,7 @@ class FormBuilderValidators {
202209
}) {
203210
assert(maxCount > 0, 'The maximum words count must be greater than 0');
204211
return (valueCandidate) {
205-
int valueWordsCount = valueCandidate?.trim().split(' ').length ?? 0;
212+
final int valueWordsCount = valueCandidate?.trim().split(' ').length ?? 0;
206213
return null != valueCandidate && valueWordsCount > maxCount
207214
? errorText ??
208215
FormBuilderLocalizations.current.maxWordsCountErrorText(maxCount)
@@ -238,13 +245,15 @@ class FormBuilderValidators {
238245
List<String> hostBlacklist = const [],
239246
}) =>
240247
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
241-
!isURL(valueCandidate,
242-
protocols: protocols,
243-
requireTld: requireTld,
244-
requireProtocol: requireProtocol,
245-
allowUnderscore: allowUnderscore,
246-
hostWhitelist: hostWhitelist,
247-
hostBlacklist: hostBlacklist)
248+
!isURL(
249+
valueCandidate,
250+
protocols: protocols,
251+
requireTld: requireTld,
252+
requireProtocol: requireProtocol,
253+
allowUnderscore: allowUnderscore,
254+
hostWhitelist: hostWhitelist,
255+
hostBlacklist: hostBlacklist,
256+
)
248257
? errorText ?? FormBuilderLocalizations.current.urlErrorText
249258
: null;
250259

@@ -293,7 +302,7 @@ class FormBuilderValidators {
293302
String? errorText,
294303
}) =>
295304
(valueCandidate) =>
296-
true == valueCandidate?.isNotEmpty && !isIP(valueCandidate!, version)
305+
true == valueCandidate?.isNotEmpty && !isIP(valueCandidate, version)
297306
? errorText ?? FormBuilderLocalizations.current.ipErrorText
298307
: null;
299308

lib/src/utils/helpers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
T? shift<T>(List<T> l) {
44
if (l.isNotEmpty) {
5-
var first = l.first;
5+
final first = l.first;
66
l.removeAt(0);
77
return first;
88
}

lib/src/utils/validators.dart

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import 'helpers.dart';
22

33
RegExp _email = RegExp(
4-
r"^((([a-z]|\d|[!#\$%&'*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$");
4+
r"^((([a-z]|\d|[!#\$%&'*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$",
5+
);
56

67
RegExp _ipv4Maybe = RegExp(r'^(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)$');
78
RegExp _ipv6 =
89
RegExp(r'^::|^::1|^([a-fA-F0-9]{1,4}::?){1,7}([a-fA-F0-9]{1,4})$');
910

1011
RegExp _creditCard = RegExp(
11-
r'^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$');
12+
r'^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$',
13+
);
1214

1315
int _maxUrlLength = 2083;
1416

@@ -25,22 +27,31 @@ bool isEmail(String str) {
2527
/// * [allowUnderscore] sets if underscores are allowed
2628
/// * [hostWhitelist] sets the list of allowed hosts
2729
/// * [hostBlacklist] sets the list of disallowed hosts
28-
bool isURL(String? str,
29-
{List<String?> protocols = const ['http', 'https', 'ftp'],
30-
bool requireTld = true,
31-
bool requireProtocol = false,
32-
bool allowUnderscore = false,
33-
List<String> hostWhitelist = const [],
34-
List<String> hostBlacklist = const []}) {
30+
bool isURL(
31+
String? str, {
32+
List<String?> protocols = const ['http', 'https', 'ftp'],
33+
bool requireTld = true,
34+
bool requireProtocol = false,
35+
bool allowUnderscore = false,
36+
List<String> hostWhitelist = const [],
37+
List<String> hostBlacklist = const [],
38+
}) {
3539
if (str == null ||
3640
str.isEmpty ||
3741
str.length > _maxUrlLength ||
3842
str.startsWith('mailto:')) {
3943
return false;
4044
}
4145
int port;
42-
String? protocol, auth, user;
43-
String host, hostname, portStr, path, query, hash;
46+
String? protocol;
47+
String? auth;
48+
String? user;
49+
String host;
50+
String hostname;
51+
String portStr;
52+
String path;
53+
String query;
54+
String hash;
4455

4556
// check protocol
4657
var split = str.split('://');
@@ -83,7 +94,7 @@ bool isURL(String? str,
8394
if (split.length > 1) {
8495
auth = shift(split);
8596
if (auth?.contains(':') ?? false) {
86-
user = shift(auth!.split(':'))!;
97+
user = shift(auth!.split(':'));
8798
if (!RegExp(r'^\S+$').hasMatch(user)) {
8899
return false;
89100
}
@@ -110,8 +121,11 @@ bool isURL(String? str,
110121
}
111122

112123
if (!isIP(host, null) &&
113-
!isFQDN(host,
114-
requireTld: requireTld, allowUnderscores: allowUnderscore) &&
124+
!isFQDN(
125+
host,
126+
requireTld: requireTld,
127+
allowUnderscores: allowUnderscore,
128+
) &&
115129
host != 'localhost') {
116130
return false;
117131
}
@@ -137,7 +151,7 @@ bool isIP(String? str, int? version) {
137151
if (!_ipv4Maybe.hasMatch(str!)) {
138152
return false;
139153
}
140-
var parts = str.split('.');
154+
final parts = str.split('.');
141155
parts.sort((a, b) => int.parse(a) - int.parse(b));
142156
return int.parse(parts[3]) <= 255;
143157
}
@@ -148,17 +162,20 @@ bool isIP(String? str, int? version) {
148162
///
149163
/// * [requireTld] sets if TLD is required
150164
/// * [allowUnderscore] sets if underscores are allowed
151-
bool isFQDN(String str,
152-
{bool requireTld = true, bool allowUnderscores = false}) {
153-
var parts = str.split('.');
165+
bool isFQDN(
166+
String str, {
167+
bool requireTld = true,
168+
bool allowUnderscores = false,
169+
}) {
170+
final parts = str.split('.');
154171
if (requireTld) {
155-
var tld = parts.removeLast();
172+
final tld = parts.removeLast();
156173
if (parts.isEmpty || !RegExp(r'^[a-z]{2,}$').hasMatch(tld)) {
157174
return false;
158175
}
159176
}
160177

161-
for (var part in parts) {
178+
for (final part in parts) {
162179
if (allowUnderscores) {
163180
if (part.contains('__')) {
164181
return false;
@@ -178,7 +195,7 @@ bool isFQDN(String str,
178195

179196
/// check if the string is a credit card
180197
bool isCreditCard(String str) {
181-
var sanitized = str.replaceAll(RegExp(r'[^0-9]+'), '');
198+
final sanitized = str.replaceAll(RegExp('[^0-9]+'), '');
182199
if (!_creditCard.hasMatch(sanitized)) {
183200
return false;
184201
}
@@ -189,13 +206,13 @@ bool isCreditCard(String str) {
189206
var shouldDouble = false;
190207

191208
for (var i = sanitized.length - 1; i >= 0; i--) {
192-
digit = sanitized.substring(i, (i + 1));
209+
digit = sanitized.substring(i, i + 1);
193210
var tmpNum = int.parse(digit);
194211

195212
if (shouldDouble == true) {
196213
tmpNum *= 2;
197214
if (tmpNum >= 10) {
198-
sum += ((tmpNum % 10) + 1);
215+
sum += (tmpNum % 10) + 1;
199216
} else {
200217
sum += tmpNum;
201218
}

0 commit comments

Comments
 (0)