1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 22:09:06 +00:00

Migrate form_app to null safety (#925)

This commit is contained in:
John Ryan
2021-10-08 17:45:46 -07:00
committed by GitHub
parent e2e2713986
commit d3c6253f85
10 changed files with 50 additions and 83 deletions

View File

@@ -6,7 +6,7 @@ import 'package:english_words/english_words.dart' as english_words;
import 'package:flutter/material.dart';
class FormValidationDemo extends StatefulWidget {
const FormValidationDemo({Key key}) : super(key: key);
const FormValidationDemo({Key? key}) : super(key: key);
@override
_FormValidationDemoState createState() => _FormValidationDemoState();
@@ -14,9 +14,9 @@ class FormValidationDemo extends StatefulWidget {
class _FormValidationDemoState extends State<FormValidationDemo> {
final _formKey = GlobalKey<FormState>();
String adjective;
String noun;
bool agreedToTerms = false;
String? adjective;
String? noun;
bool? agreedToTerms = false;
@override
Widget build(BuildContext context) {
@@ -32,7 +32,7 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
onPressed: () {
// Validate the form by getting the FormState from the GlobalKey
// and calling validate() on it.
var valid = _formKey.currentState.validate();
var valid = _formKey.currentState!.validate();
if (!valid) {
return;
}
@@ -69,7 +69,7 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
autofocus: true,
textInputAction: TextInputAction.next,
validator: (value) {
if (value.isEmpty) {
if (value!.isEmpty) {
return 'Please enter an adjective.';
}
if (english_words.adjectives.contains(value)) {
@@ -92,7 +92,7 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
// A text field that validates that the text is a noun.
TextFormField(
validator: (value) {
if (value.isEmpty) {
if (value!.isEmpty) {
return 'Please enter a noun.';
}
if (english_words.nouns.contains(value)) {
@@ -151,7 +151,7 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
formFieldState.errorText ?? "",
style: Theme.of(context)
.textTheme
.caption
.caption!
.copyWith(color: Theme.of(context).errorColor),
),
],