Repository navigation
Description
Steps to reproduce
1 - Create a simple statefull home page;
2 - Add a DropdownMenu with some options;
3 - Inform initialSelection with a selectedValue;
4 - Create one button with a pressed function that should change the value of selectedValue for null;
5 - Select one item;
6 - Press the button;
OBS: I think that I know why it happens. I checked the DropdownMenu flutter implementation and I saw that in didUpdateWidget function do not implement something when widget.initialSelection is null, of course there is a check to see if oldWidget.initialSelection != widget.initialSelection but it is just trying to find the current option in the list and effective change the value if there is. Of course I don't know if there is a reason for it, I'm just wondering that maybe this function should check if initialSelection is null to clear the controller text;
Expected results
The expected results is clean the dropdown selection UI;
Actual results
Don't clean selection.
Code sample
Code sample
import 'package:flutter/material.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String? selectedValue1;
String? selectedValue2;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('Welcome to Flutter!'),
const SizedBox(height: 20),
DropdownMenu<String>(
width: 200,
label: const Text('First Dropdown'),
onSelected: (String? value) {
setState(() {
selectedValue1 = value;
});
},
initialSelection: selectedValue1,
dropdownMenuEntries: const <DropdownMenuEntry<String>>[
DropdownMenuEntry<String>(value: 'option1', label: 'Option 1'),
DropdownMenuEntry<String>(value: 'option2', label: 'Option 2'),
DropdownMenuEntry<String>(value: 'option3', label: 'Option 3'),
],
),
const SizedBox(height: 20),
DropdownMenu<String>(
width: 200,
label: const Text('Second Dropdown'),
initialSelection: selectedValue2,
onSelected: (String? value) {
setState(() {
selectedValue2 = value;
});
},
dropdownMenuEntries: const <DropdownMenuEntry<String>>[
DropdownMenuEntry<String>(value: 'choice1', label: 'Choice 1'),
DropdownMenuEntry<String>(value: 'choice2', label: 'Choice 2'),
DropdownMenuEntry<String>(value: 'choice3', label: 'Choice 3'),
],
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
setState(() {
selectedValue2 = null;
});
},
child: const Text('Clear Second Dropdown'),
),
],
),
),
);
}
}Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.35.7, on Microsoft Windows [Version 10.0.22631.6060], locale en-US)
[√] Windows Version (11 Enterprise 64-bit, 23H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK version 36.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Professional 2022 17.13.3)
[√] Android Studio (version 2024.1)
[√] VS Code (version 1.105.1)
[√] Connected device (5 available)
[√] Network resources
• No issues found!
Activity
UriDevzera commentedon Oct 27, 2025
I can solve this using controller for the DropdownMenu. Again, I don't know if it is a issue, cause it don't crash the application and don't throw any exception. But at least is a unexpected behavior.
Thanks!
tirth-patel-nc commentedon Oct 28, 2025
@UriDevzera thanks for the report. as noted in #165877 (comment), this behavior is working as intended. however, the documentation could be improved to make this clearer and help avoid confusion.
UriDevzera commentedon Oct 28, 2025
@tirth-patel-nc Oh there is one item for it, I didn't found when I was looking for. Well that's it hehe, I will use controller to handle this as recommended. Thanks for your time.
[-][DropdownMenu][initialSelection] doesn't change the UI if I change for null[/-][+][DropdownMenu] Improve document on how to reset `selectedValue`[/+]kazbeksultanov commentedon Dec 10, 2025
@tirth-patel-nc I added PR for enhancing the documentation.
Can you take a look 🙏 ?
QuncCccccc commentedon Dec 15, 2025
Adding documentation sounds good to me! Maybe we can introduce a new property
valueorselectedValueand gradually deprecateinitialSelection? @blerouxbleroux commentedon Dec 17, 2025
This is something to consider but I'm not sure yet if it is the best option. For instance, we can also consider introducing a specific
DropdownMenuControllerwhich would be a single point to manage the text field state and the dropdown menu selected value.docs: clarify dropdown menu text clearing (#179676)
ishaquehassan commentedon Feb 27, 2026
The docs should mention that
DropdownMenuhas acontrollerparameter (TextEditingController) which can be used to programmatically reset the selection.Workaround until this is documented/fixed:
The key point is using
controller.clear()alongside setting your state variable tonull. Without passing acontroller, there's no way to imperatively clear the displayed text sinceinitialSelectiononly applies on first render and on subsequentdidUpdateWidgetcalls when the value differs — it doesn't handle thenullreset case.Ideally the docs for
DropdownMenushould have an example showing how to reset/clear the selection, anddidUpdateWidgetshould handlenullas a signal to clear the controller text.Snonky commentedon Sep 24, 2026
For those who liked the old way of controlling the state of the dropdown with a
valueparameter, here's an emulation of that with the newDropdownButton:To use, pass the same controller to
TextEditingControllerPinandDropdownMenu. The menu will always reflect the state value not its internal state. In this demo the selection is delayed by 1 second:docs: clarify programmatic clearing for DropdownMenu and add code sample
[material_ui] Document how to programmatically clear DropdownMenu sel…
[material_ui] Document how to programmatically clear DropdownMenu sel…
[material_ui] Document how to programmatically clear DropdownMenu sel…
[material_ui] Document how to programmatically clear DropdownMenu sel…
[material_ui] Document how to programmatically clear DropdownMenu sel…