Skip to content

Conversation

TahaTesser
Copy link
Member

@TahaTesser TahaTesser commented Oct 2, 2023

fixes ExpansionTile InkSplash doesn't respect Shape's borderRadius
fixes ExpansionTile.backgroundColor & ExpansionTile.collapsedBackgroundColor removes splash effect

Code sample

expand to view the code sample
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(
      debugShowCheckedModeBanner: false,
      home: Example(),
    );
  }
}

class Example extends StatelessWidget {
  const Example({super.key});

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(
          child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 24.0),
        child: ExpansionTile(
          collapsedBackgroundColor: Colors.red,
          backgroundColor: Colors.amber,
          collapsedShape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(30.0)),
            side: BorderSide(color: Colors.black, width: 2.0),
          ),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(30.0)),
            side: BorderSide(color: Colors.black, width: 2.0),
          ),
          clipBehavior: Clip.hardEdge,
          title: Text('Expansion Tile'),
          children: <Widget>[
            FlutterLogo(size: 50),
            FlutterLogo(size: 50),
            FlutterLogo(size: 50),
            FlutterLogo(size: 50),

          ],
        ),
      )),
    );
  }
}

Before

Screenshot 2023-10-02 at 16 24 36
Screenshot 2023-10-02 at 16 24 56

After

Screenshot 2023-10-02 at 16 24 06
Screenshot 2023-10-02 at 16 24 17

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

@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 2, 2023
@TahaTesser TahaTesser marked this pull request as ready for review October 9, 2023 09:20
@TahaTesser TahaTesser requested a review from HansMuller October 9, 2023 09:20
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

Note: it's clear that this PR fixes the reported problem. What about other shapes? StadiumBorder for an obvious example.

@TahaTesser
Copy link
Member Author

LGTM

Note: it's clear that this PR fixes the reported problem. What about other shapes? StadiumBorder for an obvious example.

That's a good point. Unfortunately, It's not easy to retrieve to border radius from StadiumBorder for the expanded state.
I wish we had some utility function that returns border radius from internal implementation when a ShapeBorder is provided. Here I had to add if and else, check type just to get border radius from one type of shape. Then there is also BeveledRectangleBorder to get border radius from.

Overall, I'm not happy with this current PR implementation just catering to one shape.
Do you think I should close this and come back to it later when we have more complete implementation?

@TahaTesser TahaTesser force-pushed the fix_expansion_tile_splash_effect branch from 3284360 to 10a4003 Compare October 13, 2023 12:06
@TahaTesser
Copy link
Member Author

TahaTesser commented Oct 13, 2023

FYI, I also marked existing ExpansionTile.clipBehavior property as deprecated in this PR.
It actually doesn't serve any purpose in ExpansionTile. It doesn't clip the ink well effect or the anything that needs clipping. It was added in #112218.

@HansMuller
Copy link
Contributor

I think it's OK to land this, since it fixes a common case. However please open an issue and a TODO in the code per your comment: #135855 (comment)

@TahaTesser TahaTesser force-pushed the fix_expansion_tile_splash_effect branch 2 times, most recently from 1ca73d6 to c322d2b Compare October 16, 2023 15:01
@TahaTesser
Copy link
Member Author

@HansMuller
Thanks for the suggestion. I've added a todo and updated deprecation message for the unused clipBehavior parameter.

@TahaTesser
Copy link
Member Author

Looks like this is failing "Google Testing"

@HansMuller
Copy link
Contributor

The Google testing failures were mostly the sorts of golden image test failures that you'd expect. There were a few failures that were harder to understand, notably this:

Expected Actual
Screenshot 2023-10-17 at 4 14 44 PM Screenshot 2023-10-17 at 4 15 21 PM

It's not clear why your change would affect the entire background of the ExpansionTile. I've asked the developer about it.

@TahaTesser
Copy link
Member Author

It's not clear why your change would affect the entire background of the ExpansionTile. I've asked the developer about it.

Interesting! Appreciate the help.

@HansMuller
Copy link
Contributor

@TahaTesser - The developer took a look at the test failures; replacing the ExpansionTile's Container with an Ink widget is definitely a breaking change. Could the ExpansionTile widget just create its own Material? That's how the button classes ensure that the background and ink splash are clipped to the button's shape.

@TahaTesser
Copy link
Member Author

TahaTesser commented Oct 18, 2023

Could the ExpansionTile widget just create its own Material? That's how the button classes ensure that the background and ink splash are clipped to the button's shape.

We've stayed from adding Material to ListTile for performance implications. Doing so the for the ExpansionTile would essentially be that same thing.

I've made a similar fix using the Ink widget for the ListTIle while back

selected: selected,
enabled: enabled,
child: Ink(
decoration: ShapeDecoration(
shape: shape ?? tileTheme.shape ?? const Border(),
color: _tileBackgroundColor(theme, tileTheme, defaults),
),
child: SafeArea(

I think the performance reasons to not add Material to ListTile also apply to ExpansionTile. As there could be tens of ExpansionTiles in a list view and each instance creating a Material widget in tree.

cc: @Piinks We've discussed this and agreed to not add Material widget and I documented performance considerations in the ListTIle

@TahaTesser
Copy link
Member Author

The developer took a look at the test failures; replacing the ExpansionTile's Container with an Ink widget is definitely a breaking change.

I might be able to figure something out if you could please share the test case (test code sample) that's breaking.

@HansMuller HansMuller added P2 Important issues not at the top of the work list triaged-design Triaged by Design Languages team labels Oct 18, 2023
@HansMuller
Copy link
Contributor

Not sure if a test case is forthcoming, will ask though. @Piinks suggested only creating a Material widget per ExpansionTile when a shape was specified. That might mitigate the performance impact a little. Assuming there still is a performance penalty for creating extra Material widgets and that lazy list rendering doesn't suffice to overcome whatever penalty that is.

@TahaTesser
Copy link
Member Author

TahaTesser commented Oct 19, 2023

Not sure if a test case is forthcoming, will ask though. @Piinks suggested only creating a Material widget per ExpansionTile when a shape was specified. That might mitigate the performance impact a little. Assuming there still is a performance penalty for creating extra Material widgets and that lazy list rendering doesn't suffice to overcome whatever penalty that is.

This will be great if we can mitigate the performance penalty.

Adding Material widget when shape is provided will eliminate the all the hurdles we had earlier in this PR. 🎉

  1. We can clip any provided shape including RoundedRectangleBorder, StadiumBorder, BeveledRectangleBorder.
  2. We don't need to deprecate the clipBehavior. this will be useful in the Material widget to clip the widget when necessary.

@TahaTesser TahaTesser force-pushed the fix_expansion_tile_splash_effect branch 2 times, most recently from 16d9f25 to 267511c Compare October 19, 2023 12:55
@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 #135855 at sha 267511c50a1989f626540ed696eeed164b1c31b0

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Oct 19, 2023
@TahaTesser
Copy link
Member Author

I've implemented the changes. please take a look.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the Container necessary when isShapeProvided is true?

Copy link
Member Author

@TahaTesser TahaTesser Oct 24, 2023

Choose a reason for hiding this comment

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

Thank you! Great point. I found something important with your comment. We need border side padding even for Material widget when a custom shape is provided.

Container's decoration adds padding for the top and bottom border sides.
Here you can see total height is 50px (48px + 1px (top) + 1px (bottom))

Screenshot 2023-10-24 at 11 22 40

With just DecoratedBox, there is no such border side padding.
Screenshot 2023-10-24 at 11 23 29

This illustrates what's happening. We want the bottom behavior for both default and custom shapes.
Screenshot 2023-10-24 at 11 59 57

To fix this I have wrapped the column with a Padding widget to fix the border side padding for default and custom shapes and replaced Container with DecoratedBox.
FYI, DecoratedBox is needed for the background color.

@TahaTesser TahaTesser force-pushed the fix_expansion_tile_splash_effect branch from 35ad254 to cd13c0a Compare October 24, 2023 10:29
@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 #135855 at sha 280636a0d9f83930402086ee6714a70d84b55713

@HansMuller
Copy link
Contributor

Looking into the Google testing failure. There are still some golden image diffs however they're pretty subtle:

Expected Actual Difference
Screenshot 2023-10-31 at 4 35 58 PM Screenshot 2023-10-31 at 4 36 42 PM Screenshot 2023-10-31 at 4 37 27 PM

The difference appears to be due to about a one pixel vertical shift. Not sure what would cause that.

@TahaTesser TahaTesser force-pushed the fix_expansion_tile_splash_effect branch from 280636a to c810a9e Compare November 1, 2023 15:47
@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 #135855 at sha f25c3a30dc59e0c3f73bfebe0019821a81aa9f6e

@TahaTesser TahaTesser force-pushed the fix_expansion_tile_splash_effect branch from f25c3a3 to 3a7209e Compare November 2, 2023 11:49
@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 #135855 at sha 3a7209e9eded21be0f2eb888911f17130a3680f0

@TahaTesser TahaTesser force-pushed the fix_expansion_tile_splash_effect branch from 3a7209e to 2be38a9 Compare November 7, 2023 10:19
@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 #135855 at sha 2be38a9edbb3320bd0822d932993083cec5c607f

@TahaTesser
Copy link
Member Author

TahaTesser commented Nov 7, 2023

Update on this
cc: @Piinks

This is most likely to be reverted just like multiple recent PRs with ink sparkle golden tests from me and Bruno.

I'm waiting for a workaround tried by @bleroux in #137998. If it works out, i will update the golden test in this PR otherwise remove it so it doesn't get reverted.

@TahaTesser
Copy link
Member Author

TahaTesser commented Nov 7, 2023

For context, @Piinks raised a suspicion that these PRs had to be reverted due to randomness in the sparkle effect when testing for M3.

@Piinks
Copy link
Contributor

Piinks commented Nov 13, 2023

FYI - confirmed the InkSparkle.constantTurbulenceSeedSplashFactory is the right way to eliminate randomness in testing. You can set it on the ThemeData for any relevant tests like in #137998

@TahaTesser TahaTesser force-pushed the fix_expansion_tile_splash_effect branch 2 times, most recently from ead1dab to 3180d4c Compare November 14, 2023 11:59
@TahaTesser

This comment was marked as resolved.

@TahaTesser TahaTesser force-pushed the fix_expansion_tile_splash_effect branch 4 times, most recently from ce778c5 to 49a3fb2 Compare November 15, 2023 09:03
@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 #135855 at sha 49a3fb2050bceb03fe7383e8182381a8ead0f24f

@TahaTesser TahaTesser force-pushed the fix_expansion_tile_splash_effect branch from 49a3fb2 to 5fd143d Compare November 15, 2023 13:32
@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 #135855 at sha 5fd143dcabf68bfc04076358f365257c824f8c29

@TahaTesser
Copy link
Member Author

@HansMuller
I have updated the test for ink sparkle issue. Can you please take a look if this breaks anything for the customers? :)

@TahaTesser TahaTesser force-pushed the fix_expansion_tile_splash_effect branch from 5fd143d to 507c6a6 Compare November 17, 2023 20:32
@TahaTesser TahaTesser closed this Nov 18, 2023
@TahaTesser TahaTesser deleted the fix_expansion_tile_splash_effect branch November 18, 2023 12:10
@TahaTesser
Copy link
Member Author

Closing this in favor of a fresh PR with clean history and golden files

auto-submit bot pushed a commit that referenced this pull request Jan 22, 2024
…plash ink (#141777)

This updates the previous attempt #135855 and removes the complications when testing M3 ink sparkle effect. 
Thanks to this [PR](#138757) by @Piinks 

fixes [ExpansionTile InkSplash doesn't respect Shape's borderRadius](#125779)
fixes [`ExpansionTile.backgroundColor` &  `ExpansionTile.collapsedBackgroundColor` removes splash effect](#107113)

### Code sample

<details>
<summary>expand to view the code sample</summary> 

```dart
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(
      debugShowCheckedModeBanner: false,
      home: Example(),
    );
  }
}

class Example extends StatelessWidget {
  const Example({super.key});

  @OverRide
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(
          child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 24.0),
        child: ExpansionTile(
          collapsedBackgroundColor: Color(0x25ff0000),
          backgroundColor: Color(0x250000ff),
          collapsedShape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(30.0)),
            side: BorderSide(color: Colors.black, width: 2.0),
          ),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(30.0)),
            side: BorderSide(color: Colors.black, width: 2.0),
          ),
          clipBehavior: Clip.hardEdge,
          title: Text('Expansion Tile'),
          children: <Widget>[
            FlutterLogo(size: 50),
            FlutterLogo(size: 50),
            FlutterLogo(size: 50),
            FlutterLogo(size: 50),

          ],
        ),
      )),
    );
  }
}
```

</details>

### Before

<img width="789" alt="Screenshot 2024-01-18 at 18 16 15" src="https://github.com/flutter/flutter/assets/48603081/8c6a6f1e-6986-4acf-8dec-e223a682c0d7">

<img width="789" alt="Screenshot 2024-01-18 at 18 16 44" src="https://github.com/flutter/flutter/assets/48603081/f55f6a26-2128-48a1-b24d-3c14e4f6ecdc">

### After 
<img width="789" alt="Screenshot 2024-01-18 at 18 20 27" src="https://github.com/flutter/flutter/assets/48603081/7ec8b888-7319-460d-8488-9cd44c9246a6">

<img width="789" alt="Screenshot 2024-01-18 at 18 20 53" src="https://github.com/flutter/flutter/assets/48603081/80d66d5b-7eb2-4f47-ab4d-d7f469a731fa">
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. P2 Important issues not at the top of the work list triaged-design Triaged by Design Languages team will affect goldens Changes to golden files
Projects
None yet
3 participants