8000 fix the bug of DropdownButton popup widget position error by songfei · Pull Request #65605 · flutter/flutter · GitHub
[go: up one dir, main page]

Skip to content
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

fix the bug of DropdownButton popup widget position error #65605

Closed
wants to merge 2 commits into from

Conversation

songfei
Copy link
@songfei songfei commented Sep 11, 2020

Description

This bug will happen when the Navigator is not full screen, the code:

Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Row(
        children: [
          SizedBox(
            width: 200.0,
          ),
          SizedBox(
            width: 800.0,
            child: Navigator(
              initialRoute: '/',
              onGenerateRoute: ((settings) {
                return MaterialPageRoute(builder: (context) {
                  return Container(
                    color: Colors.red,
                    child: Column(
                      children: [
                        Container(
                          width: 500.0,
                          child: DropdownButton<String>(
                            value: '1',
                            // underline: Container(height: 0),
                            isExpanded: true,
                            onChanged: (value) => setState(() => 1),
                            items: [
                              DropdownMenuItem(
                                value: '1',
                                child: Text('boy'),
                              ),
                              DropdownMenuItem(
                                value: '2',
                                child: Text('girl'),
                              )
                            ],
                          ),
                        ),
                      ],
                    ),
                  );
                });
              }),
            ),
          )
        ],
      ), 
    );

Tests

above code ok

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read [Handling breaking changes].

  • No, no existing tests failed, so this is not a breaking change.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Sep 11, 2020
@songfei songfei changed the title fix the bug of DropdownButton position error fix the bug of DropdownButton popup widget position error Sep 11, 2020
@songfei
Copy link
Author
songfei commented Sep 14, 2020

@darshankawar

Copy link < 8000 /clipboard-copy>
@kartalbas kartalbas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged manually this changes into 1.22.0-10.0.pre.269 and it works fine for me

@songfei
Copy link
Author
songfei commented Oct 1, 2020

@HansMuller @goderbauer Is there any progress?

@goderbauer
Copy link
Member

@songfei This change is missing a test. Can you please add one?

Copy link
Member
@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also missing a test case that shows that everything now works correctly when the Navigator is not in fullscreen mode.

@@ -1178,8 +1178,11 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
TextStyle get _textStyle => widget.style ?? Theme.of(context).textTheme.subtitle1;

void _handleTap() {
final RenderBox overlayBox = Overlay.of(context).context.findRenderObject() as RenderBox;
final Offset overlayOffset = overlayBox.localToGlobal(Offset.zero);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of converting both to the global coordinate system, wouldn't it be enough to convert the itemBox to the coordinate system of the overlay by providing an ancestor argument to localToGlobal?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

@songfei
Copy link
Author
songfei commented Oct 6, 2020

@goderbauer I add 2 test case and fix overlay problem, please review

@@ -1178,8 +1178,11 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
TextStyle get _textStyle => widget.style ?? Theme.of(context).textTheme.subtitle1;

void _handleTap() {
final RenderBox overlayBox = Overlay.of(context).context.findRenderObject() as RenderBox;
final Offset overlayOffset = overlayBox.localToGlobal(Offset.zero);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

),
);

final Finder buttonFinder = find.byKey(buttonKey).last;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the .last? There should only be one button with this key.

);

final Finder buttonFinder = find.byKey(buttonKey).last;
final Finder popupFinder = find.byKey(const ValueKey<String>('c')).last;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the .last?

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
// appBar: AppBar(title: const Text('Example')),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code. Either remove or comment in if it is needed.

Comment on lines +2717 to +2718
final Finder buttonFinder = find.byKey(buttonKey).last;
final Finder popupFinder = find.byKey(const ValueKey<String>('c')).last;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question about .last.

@goderbauer
Copy link
Member

Looks like there's a merge conflict. Can you rebase this to the latest master and resolve the conflict? Thanks.

@flutter-dashboard
Copy link

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@Piinks
Copy link
Contributor
Piinks commented Nov 25, 2020

This PR has not been updated in a while, so I am going to close it for now. If you would like to come back and work on this, feel free to re-open. Thank you!

@Piinks Piinks closed this Nov 25, 2020
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.

6 participants
0