Nikolas Rimikis
1 year ago
committed by
GitHub
4 changed files with 48 additions and 10 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