Nikolas Rimikis
2 years ago
2 changed files with 38 additions and 7 deletions
@ -1,11 +1,11 @@
|
||||
part of '../../neon.dart'; |
||||
|
||||
class HexColor extends Color { |
||||
HexColor(final String hexColor) |
||||
: super( |
||||
int.parse( |
||||
hexColor.toUpperCase().replaceAll('#', '').padLeft(8, 'F'), |
||||
radix: 16, |
||||
), |
||||
); |
||||
HexColor(final String hexColor) : super(_parse(hexColor)); |
||||
|
||||
static int _parse(final String hexColor) { |
||||
final formated = hexColor.toUpperCase().replaceAll('#', '').padLeft(8, 'F'); |
||||
|
||||
return int.parse(formated, radix: 16); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:neon/neon.dart'; |
||||
import 'package:test/test.dart'; |
||||
|
||||
void main() { |
||||
group('HexColor', () { |
||||
test('White', () { |
||||
final color = HexColor('#ffffffff'); |
||||
|
||||
expect(color.value, equals(Colors.white.value)); |
||||
}); |
||||
|
||||
test('Without alpha', () { |
||||
final color = HexColor('#ffffff'); |
||||
|
||||
expect(color.value, equals(Colors.white.value)); |
||||
}); |
||||
|
||||
test('Without #', () { |
||||
final color = HexColor('ffffffff'); |
||||
|
||||
expect(color.value, equals(Colors.white.value)); |
||||
}); |
||||
|
||||
test('Uppercase', () { |
||||
final color = HexColor('#FFFFFFFF'); |
||||
|
||||
expect(color.value, equals(Colors.white.value)); |
||||
}); |
||||
}); |
||||
} |
Loading…
Reference in new issue