A lightweight Dart package that allows you to apply custom opacity to colors, replicating the
functionality of the deprecated .withOpacity method in the latest Flutter SDK.
- Easily apply opacity to any
Colorobject. - Mimics the deprecated
.withOpacitymethod while ensuring compatibility with the latest Flutter SDK. - Simple and intuitive syntax.
Here’s how with_opacity looks in action:
Add with_opacity to your pubspec.yaml file:
-Import the package in your Dart file:
import 'package:with_opacity/with_opacity.dart';
-
withCustomOpacity(double opacity)
-
Applies a custom opacity to the color. The opacity must be a value between 0.0 and 1.0.
-
Parameters: opacity (double): A value between 0.0 (fully transparent) and 1.0 (fully opaque).
-
Returns: A Color object with the specified opacity applied.
Color color = Colors.red.withCustomOpacity(0.5);
- The .withOpacity method is deprecated in the latest Flutter SDK. The with_opacity package provides a modern and easy-to-use alternative, ensuring your code remains up-to-date.
Contributing: We welcome your contributions! Feel free to submit bug reports, feature requests, or pull requests to improve this package. Issues: Please report any issues you encounter using the GitHub issue tracker: https://github.com/dharmik117/with_opacity. License: This package is released under the MIT License (see LICENSE file for details). Example:
A more elaborate example showcasing both widgets can be found in the /example directory of this package.
