Skip to content

Commit dd50648

Browse files
implement use case migration guide.
1 parent 312a5bd commit dd50648

File tree

1 file changed

+174
-10
lines changed

1 file changed

+174
-10
lines changed

doc/migration.md

Lines changed: 174 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,16 +1408,180 @@ Validators.uppercase(
14081408

14091409
### Use-case validators
14101410

1411-
<!-- TODO continue from here ... -->
1412-
- `FormBuilderValidators.base64()` - requires the field's to be a valid base64 string.
1413-
- `FormBuilderValidators.colorCode()` - requires the field's value to be a valid color code.
1414-
- `FormBuilderValidators.duns()` - requires the field's value to be a valid DUNS.
1415-
- `FormBuilderValidators.isbn()` - requires the field's to be a valid ISBN.
1416-
- `FormBuilderValidators.json()` - requires the field's to be a valid json string.
1417-
- `FormBuilderValidators.languageCode()` - requires the field's to be a valid language code.
1418-
- `FormBuilderValidators.licensePlate()` - requires the field's to be a valid license plate.
1419-
- `FormBuilderValidators.uuid()` - requires the field's to be a valid uuid.
1420-
- `FormBuilderValidators.vin()` - requires the field's to be a valid VIN number.
1411+
- `FormBuilderValidators.base64()`: there is no equivalent to [this validator](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/blob/eafb7662827fe938034be6d2081c9d2844a46c10/lib/src/usecase/base64_validator.dart#L31). Something close would be:
1412+
```dart
1413+
// Old API:
1414+
FormBuilderValidator.base64(
1415+
errorText: 'error text',
1416+
);
1417+
1418+
// New API (equivalent):
1419+
bool isBase64(String value) {
1420+
try {
1421+
base64Decode(value);
1422+
return true;
1423+
} catch (e) {
1424+
return false;
1425+
}
1426+
}
1427+
1428+
Validators.satisfy(
1429+
(input)=>isBase64(input), satisfyMsg: (_)=>'error text',
1430+
);
1431+
```
1432+
- `FormBuilderValidators.colorCode()`
1433+
```dart
1434+
// Old API:
1435+
FormBuilderValidator.colorCode();
1436+
1437+
// New API:
1438+
Validators.colorCode();
1439+
```
1440+
1441+
- `FormBuilderValidators.duns()`: there is no equivalent to [this validator](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/blob/eafb7662827fe938034be6d2081c9d2844a46c10/lib/src/usecase/duns_validator.dart#L41). The equivalent would be:
1442+
```dart
1443+
// Old API:
1444+
FormBuilderValidator.duns(
1445+
errorText: 'error text',
1446+
);
1447+
1448+
// New API:
1449+
Validators.match(
1450+
RegExp(r'^\d{9}$'),
1451+
matchMsg: (_)=>'error text',
1452+
);
1453+
```
1454+
1455+
- `FormBuilderValidators.isbn()`
1456+
```dart
1457+
// Old API:
1458+
FormBuilderValidator.isbn(
1459+
errorText: 'error text',
1460+
);
1461+
1462+
// New API:
1463+
Validators.isbn(
1464+
isbnMsg: (_)=> 'error text',
1465+
);
1466+
```
1467+
- `FormBuilderValidators.json()`: there is no equivalent to [this validator](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/blob/eafb7662827fe938034be6d2081c9d2844a46c10/lib/src/usecase/json_validator.dart#L31)
1468+
```dart
1469+
// Old API:
1470+
FormBuilderValidator.json(
1471+
errorText: 'error text',
1472+
);
1473+
1474+
// New API (equivalent):
1475+
bool isJson(String value) {
1476+
try {
1477+
jsonDecode(value);
1478+
return true;
1479+
} catch (e) {
1480+
return false;
1481+
}
1482+
}
1483+
1484+
Validators.satisfy(
1485+
(input)=>isJson(input), satisfyMsg: (_)=>'error text',
1486+
);
1487+
```
1488+
- `FormBuilderValidators.languageCode()`: there is no equivalent to [this validator](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/blob/eafb7662827fe938034be6d2081c9d2844a46c10/lib/src/usecase/language_code_validator.dart#L51).
1489+
```dart
1490+
// Old API:
1491+
FormBuilderValidators.languageCode(
1492+
regex: regex,
1493+
languageCodeWhitelist: ['val1', 'val2', 'val3'],
1494+
languageCodeBlacklist: ['val4', 'val5'],
1495+
errorText: 'invalid language code',
1496+
);
1497+
1498+
// New API (expects input as String):
1499+
Validators.and([
1500+
Validators.match(
1501+
regex,
1502+
matchMsg: (_)=>'invalid language code'
1503+
),
1504+
Validators.inList(
1505+
['val1', 'val2', 'val3'],
1506+
inListMsg: (_, __) => 'invalid language code',
1507+
),
1508+
Validators.notInList(
1509+
['val1', 'val2', 'val3'],
1510+
notInListMsg: (_, __) => 'invalid language code',
1511+
),
1512+
]);
1513+
```
1514+
1515+
- `FormBuilderValidators.licensePlate()`: there is no equivalent to [this validator](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/blob/eafb7662827fe938034be6d2081c9d2844a46c10/lib/src/usecase/licenseplate_validator.dart#L52).
1516+
```dart
1517+
// Old API:
1518+
FormBuilderValidators.licensePlate(
1519+
regex: regex,
1520+
licensePlateWhitelist: ['val1', 'val2', 'val3'],
1521+
licensePlateBlacklist: ['val4', 'val5'],
1522+
errorText: 'invalid license plate',
1523+
);
1524+
1525+
// New API (expects input as String):
1526+
Validators.and([
1527+
Validators.match(
1528+
regex,
1529+
matchMsg: (_)=>'invalid license plate'
1530+
),
1531+
Validators.inList(
1532+
['val1', 'val2', 'val3'],
1533+
inListMsg: (_, __) => 'invalid license plate',
1534+
),
1535+
Validators.notInList(
1536+
['val1', 'val2', 'val3'],
1537+
notInListMsg: (_, __) => 'invalid license plate',
1538+
),
1539+
]);
1540+
```
1541+
- `FormBuilderValidators.uuid()`: there is no equivalent to [this validator](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/blob/eafb7662827fe938034be6d2081c9d2844a46c10/lib/src/usecase/uuid_validator.dart#L47).
1542+
```dart
1543+
// Old API:
1544+
FormBuilderValidator.uuid(
1545+
errorText: 'error text',
1546+
);
1547+
1548+
// New API:
1549+
Validators.match(
1550+
RegExp(
1551+
r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$',
1552+
),
1553+
matchMsg: (_)=>'error text',
1554+
);
1555+
```
1556+
1557+
- `FormBuilderValidators.vin()`: there is no equivalent to [this validator](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/blob/eafb7662827fe938034be6d2081c9d2844a46c10/lib/src/usecase/vin_validator.dart#L52).
1558+
```dart
1559+
// Old API:
1560+
FormBuilderValidators.vin(
1561+
regex: regex,
1562+
licensePlateWhitelist: ['val1', 'val2', 'val3'],
1563+
licensePlateBlacklist: ['val4', 'val5'],
1564+
errorText: 'invalid vin',
1565+
);
1566+
1567+
// New API (expects input as String):
1568+
Validators.and([
1569+
Validators.match(
1570+
regex,
1571+
matchMsg: (_)=>'invalid vin'
1572+
),
1573+
Validators.inList(
1574+
['val1', 'val2', 'val3'],
1575+
inListMsg: (_, __) => 'invalid vin',
1576+
),
1577+
Validators.notInList(
1578+
['val1', 'val2', 'val3'],
1579+
notInListMsg: (_, __) => 'invalid vin',
1580+
),
1581+
]);
1582+
```
1583+
1584+
14211585

14221586
### Extension method validators
14231587

0 commit comments

Comments
 (0)