forked from firka/flutter
Form Snippet for API Docs (#28857)
* Added code snippet for Form Class. ref:#21136 * Formatting adjustments. * Changed wording related to GlobalKey.
This commit is contained in:
@@ -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.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user