Fix bug in Autocomplete example (#127219)

This example was incorrectly throwing away results from a query when multiple queries were pending at once.   Thanks to @sun-jiao in https://github.com/flutter/flutter/pull/127019#issuecomment-1552347037 for pointing this out.

I also added a quick  `Text` widget explaining what to do to use the examples.  Since there are only three small possible `options`, it's easy to type into the field and not get any results and wonder what's wrong.
This commit is contained in:
Justin McCandless
2023-05-22 09:55:21 -07:00
committed by GitHub
parent 5b0615c6ab
commit f6f5bb9023
6 changed files with 74 additions and 11 deletions

View File

@@ -18,8 +18,14 @@ class AutocompleteExampleApp extends StatelessWidget {
appBar: AppBar(
title: const Text('Autocomplete Basic'),
),
body: const Center(
child: AutocompleteBasicExample(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: ${AutocompleteBasicExample._kOptions}.'),
const AutocompleteBasicExample(),
],
),
),
),
);

View File

@@ -18,8 +18,14 @@ class AutocompleteExampleApp extends StatelessWidget {
appBar: AppBar(
title: const Text('Autocomplete Basic User'),
),
body: const Center(
child: AutocompleteBasicUserExample(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: ${AutocompleteBasicUserExample._userOptions}.'),
const AutocompleteBasicUserExample(),
],
),
),
),
);

View File

@@ -21,8 +21,14 @@ class AutocompleteExampleApp extends StatelessWidget {
appBar: AppBar(
title: const Text('Autocomplete - async'),
),
body: const Center(
child: _AsyncAutocomplete(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.'),
const _AsyncAutocomplete(),
],
),
),
),
);

View File

@@ -24,8 +24,14 @@ class AutocompleteExampleApp extends StatelessWidget {
appBar: AppBar(
title: const Text('Autocomplete - async and debouncing'),
),
body: const Center(
child: _AsyncAutocomplete(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.'),
const _AsyncAutocomplete(),
],
),
),
),
);
@@ -59,7 +65,6 @@ class _AsyncAutocompleteState extends State<_AsyncAutocomplete > {
// If another search happened after this one, throw away these options.
if (_currentQuery != query) {
_currentQuery = null;
return null;
}
_currentQuery = null;

View File

@@ -25,8 +25,15 @@ class AutocompleteExampleApp extends StatelessWidget {
appBar: AppBar(
title: const Text('Autocomplete - async, debouncing, and network errors'),
),
body: const Center(
child: _AsyncAutocomplete(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.'),
const SizedBox(height: 32.0),
const _AsyncAutocomplete(),
],
),
),
),
);