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

[Chip] Setting background color obscures material ripple effects #73215

Closed
Tracked by #115364
NWalker1208 opened this issue Jan 2, 2021 · 8 comments · Fixed by #124673
Closed
Tracked by #115364

[Chip] Setting background color obscures material ripple effects #73215

NWalker1208 opened this issue Jan 2, 2021 · 8 comments · Fixed by #124673
Assignees
Labels
a: quality A truly polished experience f: material design flutter/packages/flutter/material repository. found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on r: fixed Issue is closed as already fixed in a newer version

Comments

@NWalker1208
Copy link
Contributor

NWalker1208 commented Jan 2, 2021

Steps to Reproduce

  1. Run flutter create chip.
  2. Update main.dart as follows:
  • Remove the FAB
  • Add two ActionChips after the counter Text widget
  • Give both chips onPressed events (_incrementCounter)
  • Give one chip a backgroundColor (Colors.red)
  1. Tap both ActionChips.

Expected results:
Both chips should have a ripple effect when you press them.
Actual results:
The chip with the background color has no ripple effect.

Cause

After looking at the Flutter source code for the RawChip widget, the issue seems to be that chips use a Container within a Material widget to display their background color. The default chip colors are not actually grey, but black or white (depending on the theme) with opacity. That opacity produces a grey color when mixed with the default Canvas color, and it allows ripple effects to show through the Container.

However, if a developer provides a background color, any non-translucent colors completely obscure the Material widget and its ripple effects. This behavior is different than that of the RaisedButton widget, which directly sets the color of its Material widget based on the given background color.

I have already created a branch that alters the RawChip widget to apply color to its Material widget instead of a Container. This fixes the issue, however, it does so by using Color.alphaBlend so that ChipTheme's default translucent colors do not need to be altered. A full solution should also correct those default colors to be actual shades of grey, so that RawChip can use the colors it is given without using alphaBlend to emulate current behavior.

Unfortunately, the changes I made do not pass existing tests, and I am not yet sufficiently familiar with Flutter testing to attempt to alter those tests. This change in behavior could also be a breaking change for some projects.

Draft pull request with my fixes: #73216

Related Issues

#41461 [Chip] Delete icon ripple not visible for Chip when background color is set

Logs
\chip>flutter analyze
Analyzing chip...
No issues found! (ran in 2.5s)
\chip>flutter doctor -v
[√] Flutter (Channel master, 1.26.0-2.0.pre.167, on Microsoft Windows [Version 10.0.19042.685], locale en-US)
    • Flutter version 1.26.0-2.0.pre.167 at d:\Developer\flutter
    • Framework revision d3a2259541 (2 days ago), 2020-12-31 15:14:03 -0500
    • Engine revision 82b4ae86d6
    • Dart version 2.12.0 (build 2.12.0-179.0.dev)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at D:\Developer\Android\SDK
    • Platform android-30, build-tools 30.0.1
    • ANDROID_SDK_ROOT = D:\Developer\Android\SDK
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.6)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.7.30611.23
    • Windows 10 SDK version 10.0.18362.0

[√] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (2 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19042.685]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 87.0.4280.88

• No issues found!
@pedromassangocode
Copy link

Hi @NWalker1208
Can you please provide a minimal complete reproducible code sample?
Thank you

@pedromassangocode pedromassangocode added in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels Jan 4, 2021
@NWalker1208
Copy link
Contributor Author

Hi @NWalker1208
Can you please provide a minimal complete reproducible code sample?
Thank you

Sure, here is the code from the steps I listed (minus the comments flutter generates):

main.dart

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, this.title = ''}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
            ActionChip(
              onPressed: _incrementCounter,
              label: Text('Without Background'),
            ),
            ActionChip(
              onPressed: _incrementCounter,
              label: Text('With Background'),
              backgroundColor: Colors.red,
            ),
          ],
        ),
      ),
    );
  }
}

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 4, 2021
@pedromassangocode
Copy link

gif

flutter doctor -v
[✓] Flutter (Channel master, 1.26.0-2.0.pre.177, on Mac OS X 10.15.7 19H2 darwin-x64, locale en)
    • Flutter version 1.26.0-2.0.pre.177 at /Users/pedromassango/dev/SDKs/flutter_master
    • Framework revision 7c26c8fbb1 (2 hours ago), 2021-01-05 01:19:03 -0500
    • Engine revision b9dc0cf1d8
    • Dart version 2.12.0 (build 2.12.0-179.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/pedromassango/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 12.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.1, Build version 12A7403
    ! CocoaPods 1.9.3 out of date (1.10.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] IntelliJ IDEA Community Edition (version 2020.3.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 52.1.5
    • Dart plugin version 203.6912

[✓] VS Code (version 1.51.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.16.0

[✓] Connected device (3 available)
    • iPhone 12 Pro (mobile) • 1EEFA5B2-DA95-49CC-AA0B-968BB248B8F3 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-1 (simulator)
    • macOS (desktop)        • macos                                • darwin-x64     • Mac OS X 10.15.7 19H2 darwin-x64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 87.0.4280.88

! Doctor found issues in 1 category.
Process finished with exit code 0

@pedromassangocode pedromassangocode changed the title [Chip] Setting background color obscures material effects [Chip] Setting background color obscures material ripple effects Jan 5, 2021
@pedromassangocode pedromassangocode added a: quality A truly polished experience f: material design flutter/packages/flutter/material repository. found in release: 1.26 Found to occur in 1.26 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on and removed in triage Presently being triaged by the triage team labels Jan 5, 2021
@michalorestes
Copy link

michalorestes commented Oct 2, 2021

Can we hope for a solution to this problem?
Wrapping ActionChip with InkWell, workaround suggested in other issues, doesn't work.

@Zohenn
Copy link

Zohenn commented Oct 21, 2022

By looking at the code you can see that RawChip uses regular Material widget under the hood, which uses ThemeData.canvasColor as the background color for its default canvas type. You can wrap your chip with Theme that sets ThemeData with your desired color as the canvasColor, like so:

Theme(
  data: Theme.of(context).copyWith(canvasColor: Colors.red),
  child: FilterChip(
    label: Text('Text'),
    onSelected: (selected) {},
  ),
),

That's still just a workaround though.

@maheshmnj
Copy link
Member

Reproducible on stable 3.3 and master 3.7

Screen.Recording.2022-12-30.at.6.05.22.PM.mov
flutter doctor -v (mac)
[✓] Flutter (Channel master, 3.7.0-3.0.pre.33, on macOS 12.6 21G115 darwin-arm64, locale en-IN)
    • Flutter version 3.7.0-3.0.pre.33 on channel master 
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5201856805 (38 minutes ago), 2022-12-05 18:27:21 -0800
    • Engine revision a309d239c4
    • Dart version 2.19.0 (build 2.19.0-463.0.dev)
    • DevTools version 2.20.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly
      to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0-rc4
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.70.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.55.20221129

[✓] Connected device (3 available)
    • iPhone 12 Pro (mobile) • 026D5789-9E78-4AD5-B1B2-3F8D4E7F65E4 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.6 21G115 darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 108.0.5359.94

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
[✓] Flutter (Channel stable, 3.3.9, on macOS 12.6 21G115 darwin-arm, locale en-IN)
    • Flutter version 3.3.9 on channel stable at /Users/mahesh/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b8f7f1f986 (24 hours ago), 2022-11-23 06:43:51 +0900
    • Engine revision 8f2221fbef
    • Dart version 2.18.5
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0-rc4
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.70.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.53.20221101

[✓] Connected device (3 available)
    • iPhone 12 Pro (mobile) • 026D5789-9E78-4AD5-B1B2-3F8D4E7F65E4 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.6 21G115 darwin-arm
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

@TahaTesser
Copy link
Member

This is fixed by #124673

Screen.Recording.2023-04-18.at.10.51.06.mov

@TahaTesser TahaTesser added the r: fixed Issue is closed as already fixed in a newer version label Apr 18, 2023
@github-actions
Copy link

github-actions bot commented May 2, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: quality A truly polished experience f: material design flutter/packages/flutter/material repository. found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on r: fixed Issue is closed as already fixed in a newer version
Projects
Status: Done (PR merged)
Development

Successfully merging a pull request may close this issue.

6 participants