Adding opacity -> alpha method to Color class (flutter/engine#13902)

This commit is contained in:
Kate Lovett
2019-11-19 09:48:04 -08:00
committed by GitHub
parent 5241bc93b9
commit 03679977c3
2 changed files with 16 additions and 0 deletions

View File

@@ -307,6 +307,14 @@ class Color {
}
}
/// Returns an alpha value representative of the provided [opacity] value.
///
/// The [opacity] value may not be null.
static int getAlphaFromOpacity(double opacity) {
assert(opacity != null);
return (opacity.clamp(0.0, 1.0) * 255).round();
}
@override
bool operator ==(dynamic other) {
if (identical(this, other))

View File

@@ -226,6 +226,14 @@ class Color {
}
}
/// Returns an alpha value representative of the provided [opacity] value.
///
/// The [opacity] value may not be null.
static int getAlphaFromOpacity(double opacity) {
assert(opacity != null);
return (opacity.clamp(0.0, 1.0) * 255).round();
}
@override
bool operator ==(dynamic other) {
if (identical(this, other)) {