Repository navigation
Description
Steps to reproduce
- Run the code sample below.
- Open the search view.
- Type
a, then immediately typeb, so that the current query becomesab. - Wait for both asynchronous requests to complete.
The request for a intentionally takes 500 ms, while the request for ab takes only 50 ms.
Expected results
Only the suggestions for the latest query, ab, should be displayed.
Actual results
The ab-result suggestion is displayed first, but is later replaced by the stale a-result when the older request completes.
SearchAnchor.suggestionsBuilder accepts FutureOr<Iterable<Widget>>, but _ViewContentState currently applies every completed result as long as the widget is mounted. It does not verify that the completed request is still the most recent request.
This can also occur between the initial suggestions request started from didChangeDependencies and later requests triggered by controller changes.
RawAutocomplete already avoids the same class of race by assigning a call ID to each asynchronous options request.
Code sample
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(home: SearchAnchorRaceExample()));
}
class SearchAnchorRaceExample extends StatelessWidget {
const SearchAnchorRaceExample({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SearchAnchor.bar(
suggestionsBuilder: (
BuildContext context,
SearchController controller,
) async {
final String query = controller.text;
if (query.isEmpty) {
return <Widget>[];
}
await Future<void>.delayed(
query == 'a'
? const Duration(milliseconds: 500)
: const Duration(milliseconds: 50),
);
return <Widget>[
ListTile(title: Text('$query-result')),
];
},
),
),
);
}
}Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.41.5, on macOS 26.0 25A8353 darwin-arm64, locale zh-Hans-CN) [88ms]
• Flutter version 3.41.5 on channel stable at /opt/homebrew/share/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 2c9eb20739 (4 months ago), 2026-03-17 16:14:01 -0700
• Engine revision 052f31d115
• Dart version 3.11.3
• DevTools version 2.54.2
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios,
cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [610ms]
• Android SDK at /Users/mac/Library/Android/sdk
• Emulator version 36.6.11.0 (build_id 15507667) (CL:N/A)
• Platform android-36.1, build-tools 36.0.0
• ANDROID_HOME = /Users/mac/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 21.0.10+-117844308-b1163.108)
• All Android licenses accepted.
[✗] Xcode - develop for iOS and macOS [111ms]
✗ Xcode installation is incomplete; a full installation is necessary for iOS and macOS development.
Download at: https://developer.apple.com/xcode/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods installed but not working.
You appear to have CocoaPods installed but it is not working.
This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
This can usually be fixed by re-installing CocoaPods.
For re-installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation
[✓] Chrome - develop for the web [24ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Proxy Configuration [23ms]
• HTTP_PROXY is set
! NO_PROXY is not set
[✓] Connected device (2 available) [123ms]
• macOS (desktop) • macos • darwin-arm64 • macOS 26.0 25A8353 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 150.0.7871.187
[✓] Network resources [1,050ms]
• All expected network resources are available.
! Doctor found issues in 2 categories.
Activity
suryaKommana2662 commentedon Jul 30, 2026
@cuishuang Thanks for report the issue. I was able to reproduce this issue locally on Windows using the provided code sample.
When I clicked the search bar and quickly typed
afollowed byb, I observed the suggestions changing froma-resulttoab-resultand then back to the stalea-result. Routing to theteam-designfor further investigation.search.mp4
Flutter Doctor Output
cuishuang commentedon Jul 30, 2026
Thank you for reproducing this. I've submitted a pull request to try and fix it; please refer to it. #190206
[material_ui] Prevent stale async suggestions in SearchAnchor (flutte…
[material_ui] Prevent stale async suggestions in SearchAnchor (flutte…
[material_ui] Prevent stale async suggestions in SearchAnchor (flutte…
github-actions commentedon Sep 10, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.