Created
May 26, 2018 19:03
-
-
Save arthurbergmz/19468f071b6716244e75d1708cc63aca to your computer and use it in GitHub Desktop.
Custom Color for Dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:ui'; | |
class CustomColor extends Color { | |
CustomColor(int color) : super(color); | |
static Color _fromHex (String hex) { | |
if (hex.startsWith("#")) hex = hex.substring(1); | |
int len = hex.length; | |
if (len == 8) hex = hex.substring(6) + hex.substring(0, 6); | |
int int16 = int.parse(hex, radix: 16); | |
if (len == 6) int16 = int16 + 0xFF000000; | |
return new Color(int16); | |
} | |
static Color fromHex(String hex) { | |
return _fromHex(hex); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment