Handle color black

pull/13/head
singerdmx 4 years ago
parent 5e25894956
commit 30d946d358
  1. 3
      app/assets/sample_data.json
  2. 11
      lib/widgets/text_line.dart

@ -74,7 +74,8 @@
}, },
{ {
"attributes":{ "attributes":{
"strike":true "strike":true,
"color":"black"
}, },
"insert":"web" "insert":"web"
}, },

@ -108,6 +108,13 @@ class TextLine extends StatelessWidget {
} }
Color _hexStringToColor(String s) { Color _hexStringToColor(String s) {
switch (s.toLowerCase()) {
case 'transparent':
return Colors.transparent;
case 'black':
return Colors.black;
}
if (s.startsWith('rgba')) { if (s.startsWith('rgba')) {
s = s.substring(5); // trim left 'rgba(' s = s.substring(5); // trim left 'rgba('
s = s.substring(0, s.length - 1); // trim right ')' s = s.substring(0, s.length - 1); // trim right ')'
@ -115,9 +122,7 @@ class TextLine extends StatelessWidget {
return Color.fromRGBO(int.parse(arr[0]), int.parse(arr[1]), return Color.fromRGBO(int.parse(arr[0]), int.parse(arr[1]),
int.parse(arr[2]), double.parse(arr[3])); int.parse(arr[2]), double.parse(arr[3]));
} }
if (s == 'transparent') {
return Colors.transparent;
}
String hex = s.replaceFirst('#', ''); String hex = s.replaceFirst('#', '');
hex = hex.length == 6 ? 'ff' + hex : hex; hex = hex.length == 6 ? 'ff' + hex : hex;
int val = int.parse(hex, radix: 16); int val = int.parse(hex, radix: 16);

Loading…
Cancel
Save