mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Add flutter_lints to form_app (#822)
This commit is contained in:
@@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:english_words/english_words.dart' as english_words;
|
||||
|
||||
class FormValidationDemo extends StatefulWidget {
|
||||
const FormValidationDemo({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_FormValidationDemoState createState() => _FormValidationDemoState();
|
||||
}
|
||||
@@ -20,13 +22,13 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('📖 Story Generator'),
|
||||
title: const Text('📖 Story Generator'),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: TextButton(
|
||||
style: TextButton.styleFrom(primary: Colors.white),
|
||||
child: Text('Submit'),
|
||||
child: const Text('Submit'),
|
||||
onPressed: () {
|
||||
// Validate the form by getting the FormState from the GlobalKey
|
||||
// and calling validate() on it.
|
||||
@@ -35,14 +37,14 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
|
||||
return;
|
||||
}
|
||||
|
||||
showDialog(
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Your story'),
|
||||
title: const Text('Your story'),
|
||||
content: Text('The $adjective developer saw a $noun'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text('Done'),
|
||||
child: const Text('Done'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
@@ -59,7 +61,7 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
|
||||
key: _formKey,
|
||||
child: Scrollbar(
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
// A text field that validates that the text is an adjective.
|
||||
@@ -75,7 +77,7 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
|
||||
}
|
||||
return 'Not a valid adjective.';
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
decoration: const InputDecoration(
|
||||
filled: true,
|
||||
hintText: 'e.g. quick, beautiful, interesting',
|
||||
labelText: 'Enter an adjective',
|
||||
@@ -84,7 +86,7 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
|
||||
adjective = value;
|
||||
},
|
||||
),
|
||||
SizedBox(
|
||||
const SizedBox(
|
||||
height: 24,
|
||||
),
|
||||
// A text field that validates that the text is a noun.
|
||||
@@ -98,7 +100,7 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
|
||||
}
|
||||
return 'Not a valid noun.';
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
decoration: const InputDecoration(
|
||||
filled: true,
|
||||
hintText: 'i.e. a person, place or thing',
|
||||
labelText: 'Enter a noun',
|
||||
@@ -107,12 +109,12 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
|
||||
noun = value;
|
||||
},
|
||||
),
|
||||
SizedBox(
|
||||
const SizedBox(
|
||||
height: 24,
|
||||
),
|
||||
// A custom form field that requires the user to check a
|
||||
// checkbox.
|
||||
FormField(
|
||||
FormField<bool>(
|
||||
initialValue: false,
|
||||
validator: (value) {
|
||||
if (value == false) {
|
||||
@@ -120,7 +122,7 @@ class _FormValidationDemoState extends State<FormValidationDemo> {
|
||||
}
|
||||
return null;
|
||||
},
|
||||
builder: (FormFieldState formFieldState) {
|
||||
builder: (formFieldState) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user