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

ExpansionTile children background color #158421

Open
wants to merge 40 commits into
base: master
Choose a base branch
from

Conversation

Halim-Elmenshawi
Copy link

Description:

This PR addresses Issue #158419 related to the ExpansionTile widget.
Add childrenBackgroundColor Property to ExpansionTile Widget for Customizing Expanded Children Background

Solution

This PR introduces a new property, childrenBackgroundColor, to the ExpansionTile widget and ExpansionTileTheme class . This new property allows developers to define a specific background color for the expanded children section, independent of the backgroundColor applied to the header.

Fixes: #158419

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Nov 10, 2024
@Piinks Piinks requested a review from QuncCccccc November 13, 2024 23:13
child: Column(
crossAxisAlignment: widget.expandedCrossAxisAlignment ?? CrossAxisAlignment.center,
children: widget.children,
child: Material(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can change Material to ColoredBox.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is extra. Why do we need this?

Copy link
Author

Choose a reason for hiding this comment

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

please see this comment

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, but it's still unclear to me why we want to isolate the children from the padding color. I thought the purpose of this PR was to change the children's background color and make them different from the header background color?

Copy link
Author

Choose a reason for hiding this comment

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

As mentioned here, our proposal is to change the padding color in children.

Copy link
Contributor

@QuncCccccc QuncCccccc Jan 29, 2025

Choose a reason for hiding this comment

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

For that example, when we specify the ListTile.tileColor, it looks like we only need a way to customize the padding color. But if we remove the tileColor assignment, I think it would be better if the children background color is the same as the "padding" color.

As for the property name, I think the original childrenBackgroundColor is better than the current padding color. Please let me know what you think:)

Copy link
Author

Choose a reason for hiding this comment

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

childrenBackgroundColor gives the impression that it will change the children's background color. However, we need to set a children's padding color separately when it differs from backgroundColor. Therefore, I believe childrenPaddingColor would be a more appropriate name.

Copy link
Contributor

Choose a reason for hiding this comment

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

childrenBackgroundColor gives the impression that it will change the children's background color.

I think this is what we are trying to fix (as the issue mentioned). Just feel it's a bit odd to only add a color for padding. My proposal would be: we add a childrenBackgroundColor, and at the same time, we remove the Material here because it's not necessary to wrap children with a Material which provides a different color (unless there's a spec indicating we should do so).

In this way, no matter whether we have paddings or not, the children background color can be customized by the new property.
Screenshot 2025-01-29 at 1 07 48 PM

Copy link
Author

Choose a reason for hiding this comment

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

What if the user needs different colors for padding and background? Currently, the user can set the children's color, but there's no way to differentiate between childrenPaddingColor and backgroundColor. That limitation is the main issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

The issue we are trying to fix is to make the children's background color customizable. If so, then the change without adding Material is sufficient. I don't think it's a good idea to add a property that only customizes the padding color (please let me know if there's such an example in the material library). This widget is Material 1 component which is pretty old and the specs also don't mention this particular use case.

What if the user needs different colors for padding and background?

There's always a way to differentiate between children's padding and children's background color. children is just a list of widgets so we can put any widget with different background colors there, right?
Screenshot 2025-01-29 at 2 21 04 PM

@Piinks
Copy link
Contributor

Piinks commented Dec 11, 2024

Hey @Halim-Elmenshawi would you like to continue working on this and address the above feedback?

@Halim-Elmenshawi
Copy link
Author

Hey @Halim-Elmenshawi would you like to continue working on this and address the above feedback?

Yes, for sure! However, I am currently on vacation. I will be back in two weeks, and I will take care of it again.

@Piinks
Copy link
Contributor

Piinks commented Dec 18, 2024

Thanks for the update! I am going to mark this as a draft in the meantime, please mark it ready for review when it is! Thanks again for contributing. :)

@Piinks Piinks marked this pull request as draft December 18, 2024 19:14
@Halim-Elmenshawi Halim-Elmenshawi marked this pull request as ready for review January 5, 2025 21:03
@Piinks Piinks requested a review from QuncCccccc January 8, 2025 18:15
@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

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.

Changes reported for pull request #158421 at sha 55ddc76

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Jan 22, 2025
@Halim-Elmenshawi
Copy link
Author

Hey @Halim-Elmenshawi, noticed in PR triage, this is currently failing the analyzer check.

Done

child: Column(
crossAxisAlignment: widget.expandedCrossAxisAlignment ?? CrossAxisAlignment.center,
children: widget.children,
child: Material(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is extra. Why do we need this?

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

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.

Changes reported for pull request #158421 at sha 35f68ba

@victorsanni victorsanni self-requested a review January 29, 2025 19:21
/// The color to display behind the expanded children section of the tile.
///
/// If this property is null, the value from [ExpansionTileThemeData.childrenPaddingColor] is
/// used. If both are null, then [backgroundColor] will be used.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's unclear what 'both' is referring to here. Maybe a better term would be 'If that is also null', where 'that' can be directly inferred as the theme color.

@@ -407,6 +408,12 @@ class ExpansionTile extends StatefulWidget {
/// [ExpansionTileThemeData].
final EdgeInsetsGeometry? childrenPadding;

/// The color to display behind the expanded children section of the tile.
Copy link
Contributor

Choose a reason for hiding this comment

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

This will need more of a description of the desired use case.

expect(childrenPaddingColor, Colors.amber);
});

testWidgets('ExpansionTile without using childrenPaddingColor Color', (
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this test just a duplicate of the test for backgroundColor? Is the test needed?

@QuncCccccc
Copy link
Contributor

Curious about your thoughts on this comment: #158421 (comment)

I still think adding background color instead of padding color makes more sense:)

@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.

@dkwingsmt dkwingsmt added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 14, 2025
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. waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds will affect goldens Changes to golden files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add backgroundColor property for children in ExpansionTile
5 participants