From 318d1b09625776984fc665caab00af8d8a6cccb6 Mon Sep 17 00:00:00 2001 From: singerdmx Date: Tue, 22 Dec 2020 00:41:33 -0800 Subject: [PATCH] Update attribute value to be private --- lib/models/documents/attribute.dart | 25 ++++++++++++++----------- lib/models/documents/nodes/line.dart | 4 ++-- lib/models/documents/style.dart | 4 ++-- lib/models/rules/insert.dart | 2 +- lib/widgets/editor.dart | 2 +- lib/widgets/raw_editor.dart | 2 +- lib/widgets/text_block.dart | 2 +- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/models/documents/attribute.dart b/lib/models/documents/attribute.dart index 896eb3a2..140ae433 100644 --- a/lib/models/documents/attribute.dart +++ b/lib/models/documents/attribute.dart @@ -9,9 +9,12 @@ enum AttributeScope { class Attribute { final String key; final AttributeScope scope; - T value; + T _value; - Attribute(this.key, this.scope, this.value); + Attribute(this.key, this.scope, this._value); + + T getValue() => _value; + setValue(T val) => _value = val; static final Map _registry = { Attribute.bold.key: Attribute.bold, @@ -49,10 +52,10 @@ class Attribute { static Attribute get h3 => HeaderAttribute(level: 3); - // "attributes":{"list":"ordered"} + // "attributes":{"list":"bullet"} static Attribute get ul => ListAttribute('bullet'); - // "attributes":{"list":"bullet"} + // "attributes":{"list":"ordered"} static Attribute get ol => ListAttribute('ordered'); bool get isInline => scope == AttributeScope.INLINE; @@ -60,7 +63,7 @@ class Attribute { bool get isBlockExceptHeader => scope == AttributeScope.BLOCK && key != Attribute.header.key; - Map toJson() => {key: value}; + Map toJson() => {key: _value}; static Attribute fromKeyValue(String key, dynamic value) { if (!_registry.containsKey(key)) { @@ -69,13 +72,13 @@ class Attribute { Attribute origin = _registry[key]; Attribute attribute = clone(origin); if (value != null) { - attribute.value = value; + attribute.setValue(value); } return attribute; } static Attribute clone(Attribute origin) { - return Attribute(origin.key, origin.scope, origin.value); + return Attribute(origin.key, origin.scope, origin.getValue()); } @override @@ -85,15 +88,15 @@ class Attribute { Attribute typedOther = other; return key == typedOther.key && scope == typedOther.scope && - value == typedOther.value; + _value == typedOther._value; } @override - int get hashCode => hash3(key, scope, value); + int get hashCode => hash3(key, scope, _value); @override String toString() { - return 'Attribute{key: $key, scope: $scope, value: $value}'; + return 'Attribute{key: $key, scope: $scope, value: $_value}'; } } @@ -118,7 +121,7 @@ class LinkAttribute extends Attribute { } class HeaderAttribute extends Attribute { - HeaderAttribute({int level = null}) : super('header', AttributeScope.BLOCK, level); + HeaderAttribute({int level}) : super('header', AttributeScope.BLOCK, level); } class ListAttribute extends Attribute { diff --git a/lib/models/documents/nodes/line.dart b/lib/models/documents/nodes/line.dart index 2727e101..c3edfe20 100644 --- a/lib/models/documents/nodes/line.dart +++ b/lib/models/documents/nodes/line.dart @@ -168,7 +168,7 @@ class Line extends Container { if (parent is Block) { Attribute parentStyle = (parent as Block).style.getBlockExceptHeader(); - if (blockStyle.value == null) { + if (blockStyle.getValue() == null) { _unwrap(); } else if (blockStyle != parentStyle) { _unwrap(); @@ -177,7 +177,7 @@ class Line extends Container { _wrap(block); block.adjust(); } - } else if (blockStyle.value != null) { + } else if (blockStyle.getValue() != null) { Block block = Block(); block.applyAttribute(blockStyle); _wrap(block); diff --git a/lib/models/documents/style.dart b/lib/models/documents/style.dart index 7d2262a8..8d63fdfb 100644 --- a/lib/models/documents/style.dart +++ b/lib/models/documents/style.dart @@ -25,7 +25,7 @@ class Style { Map toJson() => _attributes.isEmpty ? null : _attributes.map((String _, Attribute value) => - MapEntry(value.key, value.value)); + MapEntry(value.key, value.getValue())); Iterable get keys => _attributes.keys; @@ -54,7 +54,7 @@ class Style { Style merge(Attribute attribute) { Map merged = Map.from(_attributes); - if (attribute.value == null) { + if (attribute.getValue() == null) { merged.remove(attribute.key); } else { merged[attribute.key] = attribute; diff --git a/lib/models/rules/insert.dart b/lib/models/rules/insert.dart index 529dd8da..de5e5abe 100644 --- a/lib/models/rules/insert.dart +++ b/lib/models/rules/insert.dart @@ -79,7 +79,7 @@ class PreserveBlockStyleOnInsertRule extends InsertRule { return null; } - var blockStyle = {attribute.key: attribute.value}; + var blockStyle = {attribute.key: attribute.getValue()}; Map resetStyle; diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 48449d36..9a092089 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -298,7 +298,7 @@ class _QuillEditorSelectionGestureDetectorBuilder if (getEditor().widget.readOnly) { getEditor() .widget - .onLaunchUrl(segment.style.attributes[Attribute.link.key].value); + .onLaunchUrl(segment.style.attributes[Attribute.link.key].getValue()); } } } diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index c3f47320..78488813 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -609,7 +609,7 @@ class RawEditorState extends EditorState Line line, DefaultStyles defaultStyles) { Map attrs = line.style.attributes; if (attrs.containsKey(Attribute.header.key)) { - int level = attrs[Attribute.header.key].value; + int level = attrs[Attribute.header.key].getValue(); switch (level) { case 1: return defaultStyles.h1.verticalSpacing; diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index d9cf20b0..06695e26 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -145,7 +145,7 @@ class EditableTextBlock extends StatelessWidget { Map attrs = block.style.attributes; if (attrs.containsKey(Attribute.header.key)) { - int level = attrs[Attribute.header.key].value; + int level = attrs[Attribute.header.key].getValue(); switch (level) { case 1: top = defaultStyles.h1.verticalSpacing.item1;