Skip to content

Commit

Permalink
null-safety support added
Browse files Browse the repository at this point in the history
version updated to 1.0.0
  • Loading branch information
aarajput committed Apr 27, 2021
1 parent 5b36c24 commit f1300f6
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 60 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.0.0]

* Null-safety support added

## [0.1.1]

* Documentation updated
Expand Down
4 changes: 2 additions & 2 deletions example/lib/compose_validation_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class _ComposeValidationContainerState
Validators.maxLength(10, 'Characters cannot be greater than 10'),
]),
),
RaisedButton(
ElevatedButton(
child: Text('Validate compose Field'),
onPressed: () {
formKey.currentState.validate();
formKey.currentState?.validate();
},
)
],
Expand Down
4 changes: 2 additions & 2 deletions example/lib/email_validation_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class _EmailValidationContainerState extends State<EmailValidationContainer> {
),
validator: Validators.email('Invalid email address'),
),
RaisedButton(
ElevatedButton(
child: Text('Validate email Field'),
onPressed: () {
formKey.currentState.validate();
formKey.currentState?.validate();
},
)
],
Expand Down
4 changes: 2 additions & 2 deletions example/lib/max_length_validation_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class _MaxLengthValidationContainerState
),
validator: Validators.maxLength(5, 'Characters are greater than 5'),
),
RaisedButton(
ElevatedButton(
child: Text('Validate Maximum length 5 Field'),
onPressed: () {
formKey.currentState.validate();
formKey.currentState?.validate();
},
)
],
Expand Down
4 changes: 2 additions & 2 deletions example/lib/max_validation_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class _MaxValidationContainerState extends State<MaxValidationContainer> {
),
validator: Validators.max(5, 'Value greater than 5 not allowed'),
),
RaisedButton(
ElevatedButton(
child: Text('Validate Maximum 5 Field'),
onPressed: () {
formKey.currentState.validate();
formKey.currentState?.validate();
},
)
],
Expand Down
4 changes: 2 additions & 2 deletions example/lib/min_length_validation_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class _MinLengthValidationContainerState
),
validator: Validators.minLength(5, 'Characters are less than 5'),
),
RaisedButton(
ElevatedButton(
child: Text('Validate Minimum length 5 Field'),
onPressed: () {
formKey.currentState.validate();
formKey.currentState?.validate();
},
)
],
Expand Down
4 changes: 2 additions & 2 deletions example/lib/min_validation_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class _MinValidationContainerState extends State<MinValidationContainer> {
),
validator: Validators.min(5, 'Value less than 5 not allowed'),
),
RaisedButton(
ElevatedButton(
child: Text('Validate Minimum 5 Field'),
onPressed: () {
formKey.currentState.validate();
formKey.currentState?.validate();
},
)
],
Expand Down
4 changes: 2 additions & 2 deletions example/lib/pattern_validation_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class _PatternValidationContainerState
validator: Validators.patternRegExp(
RegExp(r"^[A-Za-z]+$"), 'Only alphabets are allowed'),
),
RaisedButton(
ElevatedButton(
child: Text('Validate Pattern Field'),
onPressed: () {
formKey.currentState.validate();
formKey.currentState?.validate();
},
)
],
Expand Down
4 changes: 2 additions & 2 deletions example/lib/required_validation_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class _RequiredValidationContainerState
),
validator: Validators.required('Field is required'),
),
RaisedButton(
ElevatedButton(
child: Text('Validate Required Field'),
onPressed: () {
formKey.currentState.validate();
formKey.currentState?.validate();
},
)
],
Expand Down
16 changes: 8 additions & 8 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
version: "2.3.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
charcode:
dependency: transitive
description:
Expand Down Expand Up @@ -59,28 +59,28 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.1.7"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.2"
version: "1.6.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0+1"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.5"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -113,7 +113,7 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
term_glyph:
dependency: transitive
description:
Expand Down Expand Up @@ -148,6 +148,6 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.0"
version: "0.1.1"
sdks:
dart: ">=2.2.2 <3.0.0"
4 changes: 2 additions & 2 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void main() {
// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data.startsWith('Running on:'),
(Widget widget) =>
widget is Text && widget.data?.startsWith('Running on:') == true,
),
findsOneWidget,
);
Expand Down
21 changes: 21 additions & 0 deletions lib/wc_form_validators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Validators {
///
static FormFieldValidator<String> required(String errorMessage) {
return (value) {
if (value == null) {
value = '';
}
if (value.isEmpty)
return errorMessage;
else
Expand Down Expand Up @@ -52,6 +55,9 @@ class Validators {
///
static FormFieldValidator<String> min(double min, String errorMessage) {
return (value) {
if (value == null) {
value = '';
}
if (value.trim().isEmpty)
return null;
else {
Expand Down Expand Up @@ -84,6 +90,9 @@ class Validators {
///
static FormFieldValidator<String> max(double max, String errorMessage) {
return (value) {
if (value == null) {
value = '';
}
if (value.trim().isEmpty)
return null;
else {
Expand Down Expand Up @@ -118,6 +127,9 @@ class Validators {
///
static FormFieldValidator<String> email(String errorMessage) {
return (value) {
if (value == null) {
value = '';
}
if (value.isEmpty)
return null;
else {
Expand Down Expand Up @@ -149,6 +161,9 @@ class Validators {
static FormFieldValidator<String> minLength(
int minLength, String errorMessage) {
return (value) {
if (value == null) {
value = '';
}
if (value.isEmpty) return null;

if (value.length < minLength)
Expand Down Expand Up @@ -176,6 +191,9 @@ class Validators {
static FormFieldValidator<String> maxLength(
int maxLength, String errorMessage) {
return (value) {
if (value == null) {
value = '';
}
if (value.isEmpty) return null;

if (value.length > maxLength)
Expand Down Expand Up @@ -229,6 +247,9 @@ class Validators {
static FormFieldValidator<String> patternRegExp(
RegExp pattern, String errorMessage) {
return (value) {
if (value == null) {
value = '';
}
if (value.isEmpty) return null;

if (pattern.hasMatch(value))
Expand Down
Loading

0 comments on commit f1300f6

Please sign in to comment.