Repository navigation
Closed as duplicate
Closed as duplicate
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityfound in release: 3.24Found to occur in 3.24Found to occur in 3.24found in release: 3.27Found to occur in 3.27Found to occur in 3.27frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: duplicateIssue is closed as a duplicate of an existing issueIssue is closed as a duplicate of an existing issueteam-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team
Description
Steps to reproduce
Flutter 3.19.6 works fine, Flutter 3.24.3 may break something.
- Run the example code on Windows, Linux, or MacOS.
- Click the edit filed.
Expected results
The options view should show three options. "aaa", "abc", "bcc"
Actual results
It show one option "empty".
Code sample
Code sample
import 'package:flutter/material.dart';
void main() => runApp(const AutocompleteExampleApp());
class AutocompleteExampleApp extends StatelessWidget {
const AutocompleteExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text(
'Autocomplete - optionsBuilder and optionsViewBuilder'),
),
body: const Center(
child: _AsyncAutocomplete(),
),
),
);
}
}
class _AsyncAutocomplete extends StatefulWidget {
const _AsyncAutocomplete();
@override
State<_AsyncAutocomplete> createState() => _AsyncAutocompleteState();
}
class _AsyncAutocompleteState extends State<_AsyncAutocomplete> {
Iterable<String> _options = <String>['empty'];
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Autocomplete<String>(
optionsBuilder: (TextEditingValue textEditingValue) async {
debugPrint('================= optionsBuilder, options: $_options');
if (_options.length == 1) {
return <String>['empty'];
} else {
return [..._options];
}
},
fieldViewBuilder: (
BuildContext context,
TextEditingController fieldTextEditingController,
FocusNode fieldFocusNode,
VoidCallback onFieldSubmitted,
) {
fieldTextEditingController.text = 'aaa';
fieldFocusNode.addListener(() async {
if (fieldFocusNode.hasFocus && _options.length == 1) {
setState(() {
_options = <String>['aaa', 'abc', 'bcc'];
});
}
});
return TextField(
focusNode: fieldFocusNode,
controller: fieldTextEditingController,
);
},
optionsViewBuilder: (BuildContext context,
AutocompleteOnSelected<String> onSelected, Iterable<String> options) {
debugPrint('================= optionsViewBuilder, options: $options');
return Material(
elevation: 4.0,
child: ListView(
children: options
.map((String option) => GestureDetector(
onTap: () {
onSelected(option);
},
child: ListTile(
title: Text(option),
),
))
.toList(),
),
);
},
);
}
}
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs, flutter 3.24.3
flutter: ================= optionsBuilder, options: [empty]
flutter: ================= optionsBuilder, options: [aaa, abc, bcc]
flutter: ================= optionsBuilder, options: [aaa, abc, bcc]
flutter: ================= optionsViewBuilder, options: [empty]Logs, flutter 3.19.6
flutter: ================= optionsBuilder, options: [empty]
flutter: ================= optionsViewBuilder, options: [empty]
flutter: ================= optionsBuilder, options: [aaa, abc, bcc]
flutter: ================= optionsBuilder, options: [aaa, abc, bcc]
flutter: ================= optionsViewBuilder, options: [aaa, abc, bcc]Flutter Doctor output
Doctor output
[√] Flutter (Channel stable, 3.24.3, on Microsoft Windows [Version 10.0.22631.4317], locale en-US)
• Flutter version 3.24.3 on channel stable at D:\DevEnv\flutter\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 2663184aa7 (6 weeks ago), 2024-09-11 16:27:48 -0500
• Engine revision 36335019a8
• Dart version 3.5.3
• DevTools version 2.37.3
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
• Android SDK at C:\Users\Administrator\AppData\Local\Android\sdk
X cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
X Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/to/windows-android-setup for more details.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.3)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.10.35013.160
• Windows 10 SDK version 10.0.26100.0
[√] Android Studio (version 2024.1)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.10+0--11609105)
[√] VS Code (version 1.94.2)
• VS Code at C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.98.0
[!] Proxy Configuration
• HTTP_PROXY is set
! NO_PROXY is not set
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22631.4317]
• Chrome (web) • chrome • web-javascript • Google Chrome 129.0.6668.101
• Edge (web) • edge • web-javascript • Microsoft Edge 130.0.2849.46
[√] Network resources
• All expected network resources are available.
! Doctor found issues in 2 categories.Reacted by Gustave, Regan Zhao, Danie Leeuwner, Max Weber, Thanh Nguyen, Jill Geri and gabz0r
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityfound in release: 3.24Found to occur in 3.24Found to occur in 3.24found in release: 3.27Found to occur in 3.27Found to occur in 3.27frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: duplicateIssue is closed as a duplicate of an existing issueIssue is closed as a duplicate of an existing issueteam-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team
Activity
huycozy commentedon Oct 21, 2024
Thanks for the report. I can reproduce this issue on Flutter master channel
3.27.0-1.0.pre.120and the previous stable release3.22.3.huycozy commentedon Oct 21, 2024
Bisected to PR #140285, cc @LongCatIsLooong for thoughts.
AncientPixel commentedon Feb 4, 2025
This is a production issue for us, is there any movement on this issue?
md-weber commentedon Feb 5, 2025
We tested a bit more and found that in Android 15 it works fine, in Android 13 + 14 it is broken. Also in iOS we did not have the issues.
The issue still persists in Flutter 3.27.1
Our workaround for now it to take the pre patched version into our own project and link it with the autocomplete.
LongCatIsLooong commentedon Feb 25, 2025
After reading the API docs / implementation, I think the current API / implementation expect
optionsBuilderto be a "closed". In other words, it must not capture free variables, and the output should only depend on the inputtextEditingValue. Existing issue for forcing anoptionsBuilderre-evaluation: #159443In other other words:
does not force the implementation to re-evaluate
optionsBuilder, and it shouldn't. The existing API needs to be updated.The way it "worked" before is very fragile so I don't think that should be restored - it would cause more issues than it would solve.
github-actions commentedon Mar 11, 2025
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.