Skip to content

Commit ecad156

Browse files
feat: Update exmaple to null safety
1 parent 8ed7f59 commit ecad156

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

example/lib/home_page.dart

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

44
class HomePage extends StatefulWidget {
5-
const HomePage({Key key}) : super(key: key);
5+
const HomePage({Key? key}) : super(key: key);
66

77
@override
88
HomePageState createState() => HomePageState();
@@ -42,9 +42,11 @@ class HomePageState extends State<HomePage> {
4242
/// Include your own custom `FormFieldValidator` function, if you want
4343
/// Ensures positive values only. We could also have used `FormBuilderValidators.min( 0)` instead
4444
(val) {
45-
final number = int.tryParse(val);
46-
if (number == null) return null;
47-
if (number < 0) return 'We cannot have a negative age';
45+
if (val != null) {
46+
final number = int.tryParse(val);
47+
if (number == null) return null;
48+
if (number < 0) return 'We cannot have a negative age';
49+
}
4850
return null;
4951
}
5052
]),

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void main() {
1010
}
1111

1212
class MyApp extends StatelessWidget {
13-
const MyApp({Key key}) : super(key: key);
13+
const MyApp({Key? key}) : super(key: key);
1414

1515
@override
1616
Widget build(BuildContext context) {

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
44
version: 1.0.0+1
55

66
environment:
7-
sdk: ">=2.7.0 <3.0.0"
7+
sdk: ">=2.12.0 <3.0.0"
88
flutter: ">=3.0.0"
99

1010
dependencies:

0 commit comments

Comments
 (0)