From c10b705ea9fd48b1e468b0b1ceec3dd485b6f3a2 Mon Sep 17 00:00:00 2001
From: singerdmx <singerdmx@gmail.com>
Date: Sun, 27 Dec 2020 20:34:36 -0800
Subject: [PATCH] handle rgba color string

---
 app/assets/sample_data.json |  3 +++
 lib/widgets/text_line.dart  | 11 +++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/app/assets/sample_data.json b/app/assets/sample_data.json
index a8bd9255..b420717e 100644
--- a/app/assets/sample_data.json
+++ b/app/assets/sample_data.json
@@ -66,6 +66,9 @@
       "insert":"only"
    },
    {
+      "attributes":{
+         "color":"rgba(0, 0, 0, 0.847)"
+      },
       "insert":" and "
    },
    {
diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart
index fc3737fc..2879746d 100644
--- a/lib/widgets/text_line.dart
+++ b/lib/widgets/text_line.dart
@@ -107,8 +107,15 @@ class TextLine extends StatelessWidget {
     return TextSpan(children: children, style: textStyle);
   }
 
-  Color _hexStringToColor(String hex) {
-    hex = hex.replaceFirst('#', '');
+  Color _hexStringToColor(String s) {
+    if (s.startsWith('rgba')) {
+      s = s.substring(5); // trim left 'rgba('
+      s = s.substring(0, s.length - 1); // trim right ')'
+      final arr = s.split(',').map((e) => e.trim()).toList();
+      return Color.fromRGBO(int.parse(arr[0]), int.parse(arr[1]),
+          int.parse(arr[2]), double.parse(arr[3]));
+    }
+    String hex = s.replaceFirst('#', '');
     hex = hex.length == 6 ? 'ff' + hex : hex;
     int val = int.parse(hex, radix: 16);
     return Color(val);