Skip to content

Commit 839611d

Browse files
committed
Saad Style Sheets #1
1 parent 44a8226 commit 839611d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/src/api/typed_value.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,24 @@ extension ConversionExt on Object? {
182182
}
183183

184184
/// Converts given object to [ColorRGBA] if possible. Returns null otherwise.
185-
ColorRGBA? toColorRGBA() {
185+
ColorRGBA? toColorRGBA([double alpha = 1.0]) {
186186
final value = this;
187187
if (value == null) return null;
188188
if (value is ColorRGBA) return value;
189189
if (value is String) return ColorRGBA.fromHex(value);
190-
if (value is ColorRGB) return value.toColorRGBA();
190+
if (value is ColorRGB)
191+
return ColorRGBA(r: value.r, g: value.g, b: value.b, a: alpha);
192+
193+
return null;
194+
}
195+
196+
/// Converts given object to [ColorRGB] if possible. Returns null otherwise.
197+
ColorRGB? toColorRGB() {
198+
final value = this;
199+
if (value == null) return null;
200+
if (value is ColorRGB) return value;
201+
if (value is String) return ColorRGB.fromHex(value);
202+
if (value is ColorRGBA) return ColorRGB(r: value.r, g: value.g, b: value.b);
191203

192204
return null;
193205
}

0 commit comments

Comments
 (0)