New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter 2.2.2 dropdown error when selecting #85768
Comments
Updated to new released version today, 2.2.3, and faced same issue |
@erperejildo
But I see the same behavior using the official example too (https://api.flutter.dev/flutter/material/DropdownButton-class.html), as below:
flutter doctor -v
Can you provide more details as when exactly do you see the value getting updated ? |
If you see same behaviour using the official example that's the error I was facing. It shouldn't update the value |
Hi @erperejildo, code sampleimport 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(primaryColor: Colors.blue),
darkTheme: ThemeData.dark(),
home: DropDownIssue(
title: 'DropdownForm Issue',
),
);
}
}
class DropDownIssue extends StatefulWidget {
DropDownIssue({Key? key, required this.title}) : super(key: key);
final String title;
@override
_DropDownIssueState createState() => _DropDownIssueState();
}
class _DropDownIssueState extends State<DropDownIssue> {
List<String> rentPeriods = [
'daily',
'weekly',
'bimonthly',
'monthly',
'2_months',
'quarterly',
'biannually',
'annually',
];
String? rentPeriod;
String? dropDownValue;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('DropDownButtonFormField updates state without setState'),
DropdownButtonFormField<String>(
value: rentPeriod,
items: rentPeriods.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
hint: Text(rentPeriod ?? 'daily'),
onChanged: (value) {
/// The state updates even without calling setState
// setState(() {
// rentPeriod = value;
// });
},
),
SizedBox(
height: 20,
),
Text('DropDownButton works as intended'),
DropdownButton<String>(
value: dropDownValue ?? 'One',
icon: const Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (String? newValue) {
/// commenting this wouldn't update the state of the dropdown
setState(() {
dropDownValue = newValue;
});
},
items: <String>['One', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)
],
),
);
}
}
Here's a dartapad demo of this issue. flutter doctor -v
Thank you for your contribution. |
This is working as intended, this was introduced in #37145
Looks like DropdownButtonFormField should be updated without |
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 |
Steps to Reproduce
flutter create dropdown_issue
It's the default one when we created a new project but without comments or extra widgets, just the dropdown.
This is happening in my project after updating yesterday to 2.2.2 and I was not performing any change to this page/component, it was already working before.
It also happens with a new project.
Expected results:
The dropdown shouldn't update the value when we have something like this:
This is working fine in this other example: https://api.flutter.dev/flutter/material/DropdownButton-class.html
Actual results:
The value is getting updated
Logs
The text was updated successfully, but these errors were encountered: