-
Notifications
You must be signed in to change notification settings - Fork 29.3k
Make DropdownMenu generic type non nullable #176711
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
base: master
Are you sure you want to change the base?
Make DropdownMenu generic type non nullable #176711
Conversation
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
I have 2 questions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request makes the generic type T
for DropdownMenu
and DropdownMenuFormField
non-nullable by adding an extends Object
constraint. This is a good change for type safety, as it ensures that the value
of a DropdownMenuEntry
is always non-nullable within these widgets. The documentation for onSelected
has also been updated to be more descriptive and clear, which is a great improvement. The changes are consistent and well-implemented across both dropdown_menu.dart
and dropdown_menu_form_field.dart
.
I'm in favor of making this change. import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Flutter Demo',
home: Card(
child: DropdownMenu<String?>(
dropdownMenuEntries: [
DropdownMenuEntry(value: null, label: 'Label'),
DropdownMenuEntry(value: '1', label: '1'),
DropdownMenuEntry(value: '2', label: '2'),
],
),
),
);
}
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 . Also tagged @LongCatIsLooong for review since he wrote the issue.
Is it considered a breaking change?
See https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#1-determine-if-your-change-is-a-breaking-change. It certainly could break customers, but it looks like the customer tests are passing at least. Let's see if it passes Google tests too.
Is this PR text-exempted?
I can't think of any way to test this. Can you request an exemption? See that bot's comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the fix! This will need an exemption from discord. Since the ci is passing this is not considered breaking.
/// selection was cleared / that no item was chosen. | ||
/// | ||
/// Defaults to null. If this callback itself is null, the widget still updates | ||
/// the text field with the selected label but does not notify the caller. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove the part after "but" since that sounds obvious and it's unclear who the "caller" is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I removed it in Remove extra sentence
#176753 something to consider before this gets merged. |
Fixes #175090
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assist
bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.