这是indexloc提供的服务,不要输入任何密码
Skip to content

Tweaked TabBar to provide uniform padding to all tabs in cases where only few tabs contain both icon and text #80237

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

Merged
merged 1 commit into from
May 10, 2021

Conversation

chinmoy12c
Copy link
Member

Tabs should have uniform active regions regardless of their configuration.

List which issues are fixed by this PR. You must list at least one issue.
Fixes: #80112

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Apr 11, 2021
@google-cla google-cla bot added the cla: yes label Apr 11, 2021
@chinmoy12c chinmoy12c force-pushed the issue_80112 branch 2 times, most recently from 0ab16be to 97847d3 Compare April 14, 2021 07:19
@HansMuller HansMuller requested a review from Piinks April 15, 2021 23:40
/// text or icon.
bool get tabHasTextAndIcon {
for (final Widget item in tabs) {
if (item is Tab) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This hard codes specific knowledge of another widget into TabBar, which means the TabBar will behave differently depending on its tabs.
This is something that is discussed in the style guide here: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo/b91c3c62d96814e8fbf7119be65ddeb5a9746f82#avoid-interleaving-multiple-concepts-together

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, this is true. Although, preferredSize seems to use the same kind of code here:

Size get preferredSize {
So I figured it would be okay to treat tabs differently to handle tabs in this special case? 🤔

Also, this irregularity arises because the Tabs are treated(sized) differently within a TabBar in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wow I had not seen that before. Interesting. I am going to see if I can get a second opinion on this, I was not aware of this exception to the style guide.

Also, this irregularity arises because the Tabs are treated(sized) differently within a TabBar in the first place.

It may be worth investigating if that is where our bug lies.

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

It looks like in the linked bug there is a solution to the problem by sizing the Tabs such that they are uniform, I am not sure if that may be a better solution than pressing the style guide further here - but let me see if I can get some more opinions on this.

Also, I did notice you pointed out in the bug that Material Design has an opinion about this, so maybe this is intentional.

/// text or icon.
bool get tabHasTextAndIcon {
for (final Widget item in tabs) {
if (item is Tab) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wow I had not seen that before. Interesting. I am going to see if I can get a second opinion on this, I was not aware of this exception to the style guide.

Also, this irregularity arises because the Tabs are treated(sized) differently within a TabBar in the first place.

It may be worth investigating if that is where our bug lies.

@chinmoy12c
Copy link
Member Author

It looks like in the linked bug there is a solution to the problem by sizing the Tabs such that they are uniform, I am not sure if that may be a better solution than pressing the style guide further here - but let me see if I can get some more opinions on this.

Also, I did notice you pointed out in the bug that Material Design has an opinion about this, so maybe this is intentional.

Actually I did try sizing the tabs itself earlier but that proved to be cumbersome. The problem is that for the tabs to resize themselves they would have to know:

  1. whether they are child of a TabBar(which is not always the case)
  2. Whether there are only few tabs in the parent TabBar with both icon and text.

Both of these requires a child widget to know the properties of the parent, which I guess is not possible?🤔

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Chatted with @Hixie about this, available here: https://discord.com/channels/608014603317936148/608021234516754444/832710552404230204

(it's ok to check is PreferredSizeWidget since that's an interface)

Per that discussion we should see about changing the TabBar.preferredSize to actually check for the PreferredSize widget, and wrap the Tab in one.

I have filed #80596 for tracking that.
We should investigate using a similar solution here as well since TabBar shouldn't have knowledge of Tabs.

@chinmoy12c
Copy link
Member Author

Chatted with @Hixie about this, available here: https://discord.com/channels/608014603317936148/608021234516754444/832710552404230204

(it's ok to check is PreferredSizeWidget since that's an interface)

Per that discussion we should see about changing the TabBar.preferredSize to actually check for the PreferredSize widget, and wrap the Tab in one.

I have filed #80596 for tracking that.
We should investigate using a similar solution here as well since TabBar shouldn't have knowledge of Tabs.

Hey @Piinks, I've updated the PR since #80792 has landed. Please have a look :).

Copy link
Contributor

@Piinks Piinks 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 great, thank you for embracing the yak shave! Only one nit below.

@chinmoy12c chinmoy12c force-pushed the issue_80112 branch 3 times, most recently from 8f3553c to 178fc1a Compare May 10, 2021 21:22
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Flutter_LGTM

🎉

@Piinks Piinks added waiting for tree to go green a: quality A truly polished experience labels May 10, 2021
@fluttergithubbot fluttergithubbot merged commit efd3cc5 into flutter:master May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: quality A truly polished experience 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.

[TabBar] Incorrect active region having Tabs with/without icon or text and having unequal height
3 participants