CupertinoSearchTextField: Add interactive examples (#103042)

* `CupertinoSearchTextField`: Add interactive examples

* Update docs
This commit is contained in:
Taha Tesser
2022-05-05 08:58:15 +03:00
committed by GitHub
parent 666a5c9078
commit 81fd748ac2
5 changed files with 204 additions and 47 deletions

View File

@@ -21,62 +21,24 @@ import 'text_field.dart';
/// [controller]. For example, to set the initial value of the text field, use
/// a [controller] that already contains some text such as:
///
/// {@tool snippet}
/// {@tool dartpad}
/// This examples shows how to provide initial text to a [CupertinoSearchTextField]
/// using the [controller] property.
///
/// ```dart
/// class MyPrefilledSearch extends StatefulWidget {
/// const MyPrefilledSearch({Key? key}) : super(key: key);
///
/// @override
/// State<MyPrefilledSearch> createState() => _MyPrefilledSearchState();
/// }
///
/// class _MyPrefilledSearchState extends State<MyPrefilledSearch> {
/// late TextEditingController _textController;
///
/// @override
/// void initState() {
/// super.initState();
/// _textController = TextEditingController(text: 'initial text');
/// }
///
/// @override
/// Widget build(BuildContext context) {
/// return CupertinoSearchTextField(controller: _textController);
/// }
/// }
/// ```
/// ** See code in examples/api/lib/cupertino/search_field/cupertino_search_field.0.dart **
/// {@end-tool}
///
/// It is recommended to pass a [ValueChanged<String>] to both [onChanged] and
/// [onSubmitted] parameters in order to be notified once the value of the
/// field changes or is submitted by the keyboard:
///
/// {@tool snippet}
/// {@tool dartpad}
/// This examples shows how to be notified of field changes or submitted text from
/// a [CupertinoSearchTextField].
///
/// ```dart
/// class MyPrefilledSearch extends StatefulWidget {
/// const MyPrefilledSearch({Key? key}) : super(key: key);
///
/// @override
/// State<MyPrefilledSearch> createState() => _MyPrefilledSearchState();
/// }
///
/// class _MyPrefilledSearchState extends State<MyPrefilledSearch> {
/// @override
/// Widget build(BuildContext context) {
/// return CupertinoSearchTextField(
/// onChanged: (String value) {
/// print('The text has changed to: $value');
/// },
/// onSubmitted: (String value) {
/// print('Submitted text: $value');
/// },
/// );
/// }
/// }
/// ```
/// ** See code in examples/api/lib/cupertino/search_field/cupertino_search_field.1.dart **
/// {@end-tool}
///
class CupertinoSearchTextField extends StatefulWidget {
/// Creates a [CupertinoTextField] that mimics the look and behavior of
/// UIKit's `UISearchTextField`.