mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
Add flutter_lints to form_app (#822)
This commit is contained in:
@@ -7,6 +7,8 @@ import 'package:flutter/material.dart';
|
||||
// Demonstrates how to use autofill hints. The full list of hints is here:
|
||||
// https://github.com/flutter/engine/blob/master/lib/web_ui/lib/src/engine/text_editing/autofill_hint.dart
|
||||
class AutofillDemo extends StatefulWidget {
|
||||
const AutofillDemo({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_AutofillDemoState createState() => _AutofillDemoState();
|
||||
}
|
||||
@@ -18,36 +20,36 @@ class _AutofillDemoState extends State<AutofillDemo> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Autofill'),
|
||||
title: const Text('Autofill'),
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Scrollbar(
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: AutofillGroup(
|
||||
child: Column(
|
||||
children: [
|
||||
...[
|
||||
Text('This sample demonstrates autofill. '),
|
||||
const Text('This sample demonstrates autofill. '),
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Jane',
|
||||
labelText: 'First Name',
|
||||
),
|
||||
autofillHints: [AutofillHints.givenName],
|
||||
autofillHints: const [AutofillHints.givenName],
|
||||
),
|
||||
TextFormField(
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Doe',
|
||||
labelText: 'Last Name',
|
||||
),
|
||||
autofillHints: [AutofillHints.familyName],
|
||||
autofillHints: const [AutofillHints.familyName],
|
||||
),
|
||||
TextField(
|
||||
const TextField(
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
@@ -56,7 +58,7 @@ class _AutofillDemoState extends State<AutofillDemo> {
|
||||
),
|
||||
autofillHints: [AutofillHints.email],
|
||||
),
|
||||
TextField(
|
||||
const TextField(
|
||||
keyboardType: TextInputType.phone,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
@@ -65,7 +67,7 @@ class _AutofillDemoState extends State<AutofillDemo> {
|
||||
),
|
||||
autofillHints: <String>[AutofillHints.telephoneNumber],
|
||||
),
|
||||
TextField(
|
||||
const TextField(
|
||||
keyboardType: TextInputType.streetAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
@@ -74,7 +76,7 @@ class _AutofillDemoState extends State<AutofillDemo> {
|
||||
),
|
||||
autofillHints: <String>[AutofillHints.streetAddressLine1],
|
||||
),
|
||||
TextField(
|
||||
const TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
@@ -83,7 +85,7 @@ class _AutofillDemoState extends State<AutofillDemo> {
|
||||
),
|
||||
autofillHints: <String>[AutofillHints.postalCode],
|
||||
),
|
||||
TextField(
|
||||
const TextField(
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'United States',
|
||||
@@ -91,7 +93,7 @@ class _AutofillDemoState extends State<AutofillDemo> {
|
||||
),
|
||||
autofillHints: <String>[AutofillHints.countryName],
|
||||
),
|
||||
TextField(
|
||||
const TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: InputDecoration(
|
||||
hintText: '1',
|
||||
@@ -102,7 +104,7 @@ class _AutofillDemoState extends State<AutofillDemo> {
|
||||
].expand(
|
||||
(widget) => [
|
||||
widget,
|
||||
SizedBox(
|
||||
const SizedBox(
|
||||
height: 24,
|
||||
)
|
||||
],
|
||||
|
||||
@@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
|
||||
class FormWidgetsDemo extends StatefulWidget {
|
||||
const FormWidgetsDemo({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_FormWidgetsDemoState createState() => _FormWidgetsDemoState();
|
||||
}
|
||||
@@ -23,7 +25,7 @@ class _FormWidgetsDemoState extends State<FormWidgetsDemo> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Form widgets'),
|
||||
title: const Text('Form widgets'),
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
@@ -32,16 +34,16 @@ class _FormWidgetsDemoState extends State<FormWidgetsDemo> {
|
||||
alignment: Alignment.topCenter,
|
||||
child: Card(
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 400),
|
||||
constraints: const BoxConstraints(maxWidth: 400),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
...[
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
decoration: const InputDecoration(
|
||||
filled: true,
|
||||
hintText: 'Enter a title...',
|
||||
labelText: 'Title',
|
||||
@@ -53,8 +55,8 @@ class _FormWidgetsDemoState extends State<FormWidgetsDemo> {
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
filled: true,
|
||||
hintText: 'Enter a description...',
|
||||
labelText: 'Description',
|
||||
@@ -64,7 +66,7 @@ class _FormWidgetsDemoState extends State<FormWidgetsDemo> {
|
||||
},
|
||||
maxLines: 5,
|
||||
),
|
||||
_FormDatePicker(
|
||||
_FormDatePicker<DateTime>(
|
||||
date: date,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
@@ -139,7 +141,7 @@ class _FormWidgetsDemoState extends State<FormWidgetsDemo> {
|
||||
].expand(
|
||||
(widget) => [
|
||||
widget,
|
||||
SizedBox(
|
||||
const SizedBox(
|
||||
height: 24,
|
||||
)
|
||||
],
|
||||
@@ -156,11 +158,11 @@ class _FormWidgetsDemoState extends State<FormWidgetsDemo> {
|
||||
}
|
||||
}
|
||||
|
||||
class _FormDatePicker extends StatefulWidget {
|
||||
class _FormDatePicker<T> extends StatefulWidget {
|
||||
final DateTime date;
|
||||
final ValueChanged onChanged;
|
||||
final ValueChanged<T> onChanged;
|
||||
|
||||
_FormDatePicker({
|
||||
const _FormDatePicker({
|
||||
this.date,
|
||||
this.onChanged,
|
||||
});
|
||||
@@ -191,7 +193,7 @@ class _FormDatePickerState extends State<_FormDatePicker> {
|
||||
],
|
||||
),
|
||||
TextButton(
|
||||
child: Text('Edit'),
|
||||
child: const Text('Edit'),
|
||||
onPressed: () async {
|
||||
var newDate = await showDatePicker(
|
||||
context: context,
|
||||
|
||||
@@ -11,10 +11,10 @@ class MockClient extends Mock implements http.Client {
|
||||
MockClient() {
|
||||
when(post('https://example.com/signin', body: anyNamed('body')))
|
||||
.thenAnswer((answering) {
|
||||
var body = answering.namedArguments[Symbol('body')];
|
||||
dynamic body = answering.namedArguments[const Symbol('body')];
|
||||
|
||||
if (body != null && body is String) {
|
||||
var decodedJson = json.decode(body);
|
||||
var decodedJson = json.decode(body) as Map<String, String>;
|
||||
|
||||
if (decodedJson['email'] == 'root' &&
|
||||
decodedJson['password'] == 'password') {
|
||||
|
||||
@@ -29,9 +29,10 @@ class FormData {
|
||||
class SignInHttpDemo extends StatefulWidget {
|
||||
final http.Client httpClient;
|
||||
|
||||
SignInHttpDemo({
|
||||
const SignInHttpDemo({
|
||||
this.httpClient,
|
||||
});
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SignInHttpDemoState createState() => _SignInHttpDemoState();
|
||||
@@ -44,19 +45,19 @@ class _SignInHttpDemoState extends State<SignInHttpDemo> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Sign in Form'),
|
||||
title: const Text('Sign in Form'),
|
||||
),
|
||||
body: Form(
|
||||
child: Scrollbar(
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
...[
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
autofocus: true,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
decoration: const InputDecoration(
|
||||
filled: true,
|
||||
hintText: 'Your email address',
|
||||
labelText: 'Email',
|
||||
@@ -66,7 +67,7 @@ class _SignInHttpDemoState extends State<SignInHttpDemo> {
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
decoration: const InputDecoration(
|
||||
filled: true,
|
||||
labelText: 'Password',
|
||||
),
|
||||
@@ -76,7 +77,7 @@ class _SignInHttpDemoState extends State<SignInHttpDemo> {
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text('Sign in'),
|
||||
child: const Text('Sign in'),
|
||||
onPressed: () async {
|
||||
// Use a JSON encoded string to send
|
||||
var result = await widget.httpClient.post(
|
||||
@@ -96,7 +97,7 @@ class _SignInHttpDemoState extends State<SignInHttpDemo> {
|
||||
].expand(
|
||||
(widget) => [
|
||||
widget,
|
||||
SizedBox(
|
||||
const SizedBox(
|
||||
height: 24,
|
||||
)
|
||||
],
|
||||
@@ -110,13 +111,13 @@ class _SignInHttpDemoState extends State<SignInHttpDemo> {
|
||||
}
|
||||
|
||||
void _showDialog(String message) {
|
||||
showDialog(
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(message),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text('OK'),
|
||||
child: const Text('OK'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -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