Repository navigation
Closed
Labels
r: invalidIssue is closed as not validIssue is closed as not valid
Description
Steps to reproduce
Run the code, and click the reset button to clear the content of the dropdowns.
Expected results
Clicking on the reset button resets both dropdowns. DropdownMenu doesnt.
Actual results
Only the DropdownButton gets reset.
Code sample
Code sample
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(home: DropdownExample());
}
}
class DropdownExample extends StatefulWidget {
@override
State<DropdownExample> createState() => _DropdownExampleState();
}
class _DropdownExampleState extends State<DropdownExample> {
final List<String> items = ['Apple', 'Banana', 'Cherry'];
String? selectedMenuItem = 'Apple';
String? selectedButtonItem = "Apple";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Dropdown Demo')),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
DropdownMenu<String>(
initialSelection: selectedMenuItem,
onSelected: (value) => setState(() => selectedMenuItem = value),
dropdownMenuEntries:
items
.map((e) => DropdownMenuEntry<String>(value: e, label: e))
.toList(),
),
SizedBox(height: 20),
DropdownButton<String>(
hint: Text('Select an item'),
value: selectedButtonItem,
onChanged: (value) => setState(() => selectedButtonItem = value),
items:
items
.map(
(e) =>
DropdownMenuItem<String>(value: e, child: Text(e)),
)
.toList(),
),
SizedBox(height: 40),
ElevatedButton(
onPressed: () {
setState(() {
selectedMenuItem = null;
selectedButtonItem = null;
});
},
child: Text('Reset Dropdowns'),
),
],
),
),
);
}
}
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
DartPad with Flutter 3.29.2 and Dart 3.7.2
Metadata
Metadata
Assignees
Labels
r: invalidIssue is closed as not validIssue is closed as not valid
Activity
maheshj01 commentedon Mar 26, 2025
@ndonkoHenri you should try using the texteditingController to reset the field, selectedMenuItem in your field is being used for
initialSelectionupdating it won't change the selectedItem valuecode sample
Closing as this is working as intended, Incase you disagree please feel free to write in the comments and we will reopen it.
github-actions commentedon Apr 9, 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.