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

[bug/problem] Deprecation Fix for withOpacity in Flutter 3.27.2 #585

Open
AyushMaji opened this issue Feb 20, 2025 · 1 comment
Open

[bug/problem] Deprecation Fix for withOpacity in Flutter 3.27.2 #585

AyushMaji opened this issue Feb 20, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@AyushMaji
Copy link

AyushMaji commented Feb 20, 2025

Describe the bug/problem

In our app, the function Theme.of(context).colorScheme.surfaceContainerHighest.withOpacity(0.5) is used 48 times across 32 pages to apply opacity to colors. However, in Flutter version 3.27.2 and later, the withOpacity function has been deprecated. This requires updating our code to align with the latest Flutter version.

Steps to Reproduce the bug/problem

Screenshot - https://drive.google.com/file/d/1Zxj_vd1-ufqfxvTMRn4GQ3970V8s4ZjW/view?usp=sharing

Solution

To resolve this issue, we can replace the deprecated function with:
Theme.of(context).colorScheme.surfaceContainerHighest.withAlpha((0.5 * 255).round());
In Flutter's newer versions, withOpacity expects an integer-based opacity value. Since opacity values typically range from 0.0 to 1.0, multiplying by 255 converts it into an integer scale (0 to 255), which aligns with the updated API requirements.

Device Info (The device where you encountered this issue)

  • OS: MacOS
  • Version: Sequoia 15.0.1
@AyushMaji AyushMaji added the bug Something isn't working label Feb 20, 2025
@AyushMaji
Copy link
Author

i have fixed this issue and made a PR #586 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant