Unverified Commit 64d31016 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Form Snippet for API Docs (#28857)

* Added code snippet for Form Class. ref:#21136

* Formatting adjustments.

* Changed wording related to GlobalKey.
parent acf51d8e
......@@ -15,6 +15,53 @@ import 'will_pop_scope.dart';
/// descendant of this [Form]. To obtain the [FormState], you may use [Form.of]
/// with a context whose ancestor is the [Form], or pass a [GlobalKey] to the
/// [Form] constructor and call [GlobalKey.currentState].
///
/// {@tool snippet --template=stateful_widget_material}
/// This example shows a [Form] with one [TextFormField] and a [RaisedButton]. A
/// [GlobalKey] is used here to identify the [Form] and validate input.
///
/// ```dart
/// final _formKey = GlobalKey<FormState>();
///
/// @override
/// Widget build(BuildContext context) {
/// return Form(
/// key: _formKey,
/// child: Column(
/// crossAxisAlignment: CrossAxisAlignment.start,
/// children: <Widget>[
/// TextFormField(
/// validator: (value) {
/// if (value.isEmpty) {
/// return 'Please enter some text';
/// }
/// },
/// ),
/// Padding(
/// padding: const EdgeInsets.symmetric(vertical: 16.0),
/// child: RaisedButton(
/// onPressed: () {
/// // Validate will return true if the form is valid, or false if
/// // the form is invalid.
/// if (_formKey.currentState.validate()) {
/// // Process data.
/// }
/// },
/// child: Text('Submit'),
/// ),
/// ),
/// ],
/// ),
/// );
/// }
/// ```
/// {@end-tool}
///
/// See also:
///
/// * [GlobalKey], a key that is unique across the entire app.
/// * [FormField], a single form field widget that maintains the current state.
/// * [TextFormField], a convenience widget that wraps a [TextField] widget in a [FormField].
class Form extends StatefulWidget {
/// Creates a container for form fields.
///
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment