12 lines
435 B
Dart
12 lines
435 B
Dart
import 'package:flutter/material.dart' show Color;
|
|
|
|
extension HexColor on Color {
|
|
/// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#".
|
|
static Color fromHex(String hexString) {
|
|
final buffer = StringBuffer();
|
|
if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
|
|
buffer.write(hexString.replaceFirst('#', ''));
|
|
return Color(int.parse(buffer.toString(), radix: 16));
|
|
}
|
|
}
|