Skip to content

Instantly share code, notes, and snippets.

@arthurbergmz
Created May 26, 2018 19:03
Show Gist options
  • Save arthurbergmz/19468f071b6716244e75d1708cc63aca to your computer and use it in GitHub Desktop.
Save arthurbergmz/19468f071b6716244e75d1708cc63aca to your computer and use it in GitHub Desktop.
Custom Color for Dart
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