Skip to content

Commit 359c8d2

Browse files
add examples and more migrations
1 parent db85c06 commit 359c8d2

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

doc/migration.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,33 @@ Validators.ip(
965965
);
966966
```
967967

968-
- `FormBuilderValidators.latitude()` - requires the field's to be a valid latitude.
969-
- `FormBuilderValidators.longitude()` - requires the field's to be a valid longitude.
968+
- `FormBuilderValidators.latitude()`: there is no equivalent to [this validator](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/blob/17e982bb849dc68365f8fbc93d5a2323ee891c89/lib/src/network/latitude_validator.dart#L40). But something close would be:
969+
```dart
970+
// Old API:
971+
FormBuilderValidators.latitude();
972+
973+
// New API:
974+
Validators.transformAndValidate(
975+
(String input) => input.replaceAll(',', '.'),
976+
next: Validators.double(Validators.between(-90, 90)),
977+
);
978+
979+
```
980+
981+
- `FormBuilderValidators.longitude()`: there is no equivalent to [this validator](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/blob/17e982bb849dc68365f8fbc93d5a2323ee891c89/lib/src/network/longitude_validator.dart#L40). But something close would be:
982+
```dart
983+
// Old API:
984+
FormBuilderValidators.longitude();
985+
986+
// New API:
987+
Validators.transformAndValidate(
988+
(String input) => input.replaceAll(',', '.'),
989+
next: Validators.double(Validators.between(-180, 180)),
990+
);
991+
992+
```
993+
994+
TODO continue from here...
970995
- `FormBuilderValidators.macAddress()` - requires the field's to be a valid MAC address.
971996
- `FormBuilderValidators.phoneNumber()` - requires the field's value to be a valid phone number.
972997
- `FormBuilderValidators.portNumber()` - requires the field's to be a valid port number.

example/lib/generic_examples.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,28 @@ class GenericExamplesPage extends StatelessWidget {
273273
textInputAction: TextInputAction.done,
274274
autovalidateMode: AutovalidateMode.always,
275275
),
276+
TextFormField(
277+
decoration: const InputDecoration(
278+
labelText: 'Latitude',
279+
prefixIcon: Icon(Icons.add_location),
280+
),
281+
validator: V.required(V.transformAndValidate(
282+
(String input) => input.replaceAll(',', '.'),
283+
next: V.double(V.between(-90, 90)))),
284+
textInputAction: TextInputAction.done,
285+
autovalidateMode: AutovalidateMode.always,
286+
),
287+
TextFormField(
288+
decoration: const InputDecoration(
289+
labelText: 'Longitude',
290+
prefixIcon: Icon(Icons.add_location),
291+
),
292+
validator: V.required(V.transformAndValidate(
293+
(String input) => input.replaceAll(',', '.'),
294+
next: V.double(V.between(-180, 180)))),
295+
textInputAction: TextInputAction.done,
296+
autovalidateMode: AutovalidateMode.always,
297+
),
276298
],
277299
),
278300
),

0 commit comments

Comments
 (0)