-
Notifications
You must be signed in to change notification settings - Fork 7.7k
/
Copy pathautofill.dart
111 lines (106 loc) · 4.39 KB
/
autofill.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
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({super.key});
@override
State<AutofillDemo> createState() => _AutofillDemoState();
}
class _AutofillDemoState extends State<AutofillDemo> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Autofill')),
body: Form(
key: _formKey,
child: Scrollbar(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: AutofillGroup(
child: Column(
children: [
...[
const Text('This sample demonstrates autofill. '),
TextFormField(
autofocus: true,
textInputAction: TextInputAction.next,
decoration: const InputDecoration(
hintText: 'Jane',
labelText: 'First Name',
),
autofillHints: const [AutofillHints.givenName],
),
TextFormField(
textInputAction: TextInputAction.next,
decoration: const InputDecoration(
hintText: 'Doe',
labelText: 'Last Name',
),
autofillHints: const [AutofillHints.familyName],
),
const TextField(
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
hintText: '[email protected]',
labelText: 'Email',
),
autofillHints: [AutofillHints.email],
),
const TextField(
keyboardType: TextInputType.phone,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
hintText: '(123) 456-7890',
labelText: 'Telephone',
),
autofillHints: [AutofillHints.telephoneNumber],
),
const TextField(
keyboardType: TextInputType.streetAddress,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
hintText: '123 4th Ave',
labelText: 'Street Address',
),
autofillHints: [AutofillHints.streetAddressLine1],
),
const TextField(
keyboardType: TextInputType.number,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
hintText: '12345',
labelText: 'Postal Code',
),
autofillHints: [AutofillHints.postalCode],
),
const TextField(
textInputAction: TextInputAction.next,
decoration: InputDecoration(
hintText: 'United States',
labelText: 'Country',
),
autofillHints: [AutofillHints.countryName],
),
const TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: '1',
labelText: 'Country Code',
),
autofillHints: [AutofillHints.countryCode],
),
].expand((widget) => [widget, const SizedBox(height: 24)]),
],
),
),
),
),
),
);
}
}