Przeglądaj źródła

chore: small code improvements

Enzo Lizama 2 lat temu
rodzic
commit
bf9f6ac13f

+ 8 - 6
frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/attributes_extension.dart

@@ -17,9 +17,9 @@ extension NodeAttributesExtensions on Attributes {
     return containsKey(BuiltInAttributeKey.quote);
   }
 
-  int? get number {
+  num? get number {
     if (containsKey(BuiltInAttributeKey.number) &&
-        this[BuiltInAttributeKey.number] is int) {
+        this[BuiltInAttributeKey.number] is num) {
       return this[BuiltInAttributeKey.number];
     }
     return null;
@@ -27,7 +27,7 @@ extension NodeAttributesExtensions on Attributes {
 
   bool get code {
     if (containsKey(BuiltInAttributeKey.code) &&
-        this[BuiltInAttributeKey.code] == true) {
+        this[BuiltInAttributeKey.code] is bool) {
       return this[BuiltInAttributeKey.code];
     }
     return false;
@@ -63,11 +63,14 @@ extension DeltaAttributesExtensions on Attributes {
         this[BuiltInAttributeKey.strikethrough] == true);
   }
 
+  static const whiteInt = 0XFFFFFFFF;
+
   Color? get color {
     if (containsKey(BuiltInAttributeKey.color) &&
         this[BuiltInAttributeKey.color] is String) {
       return Color(
-        int.parse(this[BuiltInAttributeKey.color]),
+        // If the parse fails returns white by default
+        int.tryParse(this[BuiltInAttributeKey.color]) ?? whiteInt,
       );
     }
     return null;
@@ -77,8 +80,7 @@ extension DeltaAttributesExtensions on Attributes {
     if (containsKey(BuiltInAttributeKey.backgroundColor) &&
         this[BuiltInAttributeKey.backgroundColor] is String) {
       return Color(
-        int.parse(this[BuiltInAttributeKey.backgroundColor]),
-      );
+          int.tryParse(this[BuiltInAttributeKey.backgroundColor]) ?? whiteInt);
     }
     return null;
   }