8000 Make DropdownMenu generic type non nullable by ValentinVignal · Pull Request #176711 · flutter/flutter · GitHub
[go: up one dir, main page]

Skip to content

Conversation

ValentinVignal
Copy link
Contributor

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.

@flutter-dashboard
Copy link

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.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Oct 8, 2025
@ValentinVignal
Copy link
Contributor Author

I have 2 questions:

  1. Is it considered a breaking change?
  2. Is this PR text-exempted?

Copy link
Contributor
@gemini-code-assist gemini-code-assist bot left a 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.

@bleroux
Copy link
Contributor
bleroux commented Oct 8, 2025

I'm in favor of making this change.
It will avoid confusion and clarify that DropdownMenuEntry.value cannot be null.
It is probably a breaking change as previously the following code was possible:

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'),
          ],
        ),
      ),
    );
  }
}

Copy link
Contributor
@justinmc justinmc left a 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.

Copy link
Contributor
@LongCatIsLooong LongCatIsLooong left a 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.
Copy link
Contributor

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

Copy link
Contributor Author

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

@nebkat
Copy link
nebkat commented Oct 9, 2025

#176753 something to consider before this gets merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add documentation to DropdownMenu.onSelected and add appropriate type constraints
5 participants
0