1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 22:38:42 +00:00
Files
samples/experimental/form_app/lib/src/autofill.dart
John Ryan af5be70f34 add form_app (#463)
* add form_app

* revert unrelated changes

* use links in README

* remove unnecessary type annotation

* Remove GlobalKey for sign_in_http sample

* reword comment

* run package:copywriter

* use relative import

* fix quotes

* Add punctuation

* make sure setState() is used in form_widgets sample

* avoid first person pronoun

* store date state in parent widget in form_widgets.dart
2020-06-12 12:38:46 -07:00

106 lines
3.7 KiB
Dart

// 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 {
@override
_AutofillDemoState createState() => _AutofillDemoState();
}
class _AutofillDemoState extends State<AutofillDemo> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Autofill'),
),
body: Form(
key: _formKey,
child: Scrollbar(
child: SingleChildScrollView(
padding: EdgeInsets.all(16),
child: AutofillGroup(
child: Column(
children: [
...[
Text('This sample demonstrates autofill. '),
TextFormField(
decoration: InputDecoration(
hintText: 'Jane',
labelText: 'First Name',
),
autofillHints: [AutofillHints.givenName],
),
TextFormField(
decoration: InputDecoration(
hintText: 'Doe',
labelText: 'Last Name',
),
autofillHints: [AutofillHints.familyName],
),
TextField(
decoration: InputDecoration(
hintText: 'foo@example.com',
labelText: 'Email',
),
autofillHints: [AutofillHints.email],
),
TextField(
decoration: InputDecoration(
hintText: '(123) 456-7890',
labelText: 'Telephone',
),
autofillHints: <String>[AutofillHints.telephoneNumber],
),
TextField(
decoration: InputDecoration(
hintText: '123 4th Ave',
labelText: 'Street Address',
),
autofillHints: <String>[AutofillHints.streetAddressLine1],
),
TextField(
decoration: InputDecoration(
hintText: '12345',
labelText: 'Postal Code',
),
autofillHints: <String>[AutofillHints.postalCode],
),
TextField(
decoration: InputDecoration(
hintText: 'United States',
labelText: 'Country',
),
autofillHints: <String>[AutofillHints.countryName],
),
TextField(
decoration: InputDecoration(
hintText: '1',
labelText: 'Country Code',
),
autofillHints: <String>[AutofillHints.countryCode],
),
].expand(
(widget) => [
widget,
SizedBox(
height: 24,
)
],
)
],
),
),
),
),
),
);
}
}