Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: small code improvements

Enzo Lizamabf9f6ac13f75
diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/attributes_extension.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/attributes_extension.dart
index c80753b217..b8970d8225 100644
--- a/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/attributes_extension.dart
+++ b/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;
}