From bf9f6ac13f75a80a061fd93f2d5d4f465cd41b61 Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Tue, 4 Oct 2022 11:37:59 -0500 Subject: [PATCH] chore: small code improvements --- .../lib/src/extensions/attributes_extension.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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; }