Skip to content

Commit 7a324b7

Browse files
refactor: split files and tests
1 parent fb3eb5f commit 7a324b7

7 files changed

+1029
-878
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Also included is the `l10n` / `i18n` of error text messages to multiple language
4949
This package comes with several most common `FormFieldValidator`s such as required, numeric, mail,
5050
URL, min, max, minLength, maxLength, minWordsCount, maxWordsCount, IP, credit card, etc., with default `errorText` messages.
5151

52-
Available built-in helper validators:
52+
### Helper validators
5353

5454
- `FormBuilderValidators.compose()` - runs each validator against the value provided.
5555
- `FormBuilderValidators.conditional()` - conditionally runs a validator against the value provided.
@@ -60,7 +60,7 @@ Available built-in helper validators:
6060
- `FormBuilderValidators.skipWhen()` - runs the validator and skips the validation when a certain condition is met.
6161
- `FormBuilderValidators.defaultValue()` - runs the validator using the default value when the provided value is null.
6262

63-
Available built-in type validators include:
63+
### Type validators
6464

6565
- `FormBuilderValidators.equal()` - requires the field's value to be equal to the provided object.
6666
- `FormBuilderValidators.integer()` - requires the field's value to be an integer.
@@ -95,7 +95,7 @@ Available built-in type validators include:
9595
- `FormBuilderValidators.unique()` - requires the field's to be unique in the provided list.
9696
- `FormBuilderValidators.singleLine()` - requires the field's string to be a single line of text.
9797

98-
Available built-in use-case validators include:
98+
### Use-case validators
9999

100100
- `FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
101101
- `FormBuilderValidators.creditCardExpirationDate()` - requires the field's value to be a valid credit card expiration date and can check if not expired yet.
@@ -119,7 +119,7 @@ Available built-in use-case validators include:
119119
- `FormBuilderValidators.bic()` - requires the field's to be an valid BIC.
120120
- `FormBuilderValidators.isbn()` - requires the field's to be an valid ISBN.
121121

122-
Available extension methods used for chaining validators:
122+
## Extension methods used for chaining validators
123123

124124
- `FormBuilderValidator.and()` - Combines the current validator with another validator using logical AND.
125125
- `FormBuilderValidator.or()` - Combines the current validator with another validator using logical OR.

lib/form_builder_validators.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ export 'localization/intl/messages_uk.dart';
3232
export 'localization/intl/messages_zh.dart';
3333
export 'localization/l10n.dart';
3434
export 'src/form_builder_validators.dart';
35+
export 'src/form_field_validator_extensions.dart';

lib/src/form_builder_validators.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import 'package:flutter/material.dart';
2-
import '../form_builder_validators.dart';
1+
import 'package:flutter/widgets.dart';
32

3+
import '../form_builder_validators.dart';
44
import 'utils/helpers.dart';
55
import 'utils/validators.dart';
66

test/helper_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_localizations/flutter_localizations.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
import 'package:form_builder_validators/localization/l10n.dart';
5+
6+
/// Test Harness for running Validations
7+
Future<void> testValidations(
8+
WidgetTester tester,
9+
void Function(BuildContext) validations,
10+
) async {
11+
await tester.pumpWidget(
12+
MaterialApp(
13+
localizationsDelegates: const [
14+
FormBuilderLocalizations.delegate,
15+
GlobalMaterialLocalizations.delegate,
16+
GlobalWidgetsLocalizations.delegate,
17+
],
18+
home: Builder(
19+
builder: (BuildContext context) {
20+
// Exercise validations using the provided context
21+
validations(context);
22+
// The builder function must return a widget.
23+
return const Placeholder();
24+
},
25+
),
26+
),
27+
);
28+
29+
// Critical to pumpAndSettle to let Builder build to exercise validations
30+
await tester.pumpAndSettle();
31+
}

0 commit comments

Comments
 (0)