From 0d38e8787dd0e44b958aa93a3908192f1dcda124 Mon Sep 17 00:00:00 2001 From: Ellet <73608287+freshtechtips@users.noreply.github.com> Date: Sun, 5 Nov 2023 03:21:53 +0300 Subject: [PATCH] Follow dart best practices by using and remove as well since they are not used --- CHANGELOG.md | 3 + analysis_options.yaml | 3 +- example/lib/pages/home_page.dart | 10 +-- .../analysis_options.yaml | 2 +- flutter_quill_extensions/pubspec.yaml | 2 +- lib/src/models/documents/attribute.dart | 62 +++++++++---------- lib/src/models/documents/document.dart | 16 ++--- lib/src/models/documents/history.dart | 4 +- lib/src/models/documents/nodes/container.dart | 8 +-- .../models/documents/nodes/embeddable.dart | 4 +- lib/src/models/documents/nodes/leaf.dart | 6 +- lib/src/models/documents/nodes/line.dart | 36 +++++------ lib/src/models/documents/style.dart | 6 +- lib/src/models/quill_delta.dart | 20 +++--- lib/src/models/rules/delete.dart | 2 +- lib/src/models/rules/format.dart | 6 +- lib/src/models/rules/insert.dart | 2 +- lib/src/models/rules/rule.dart | 2 +- lib/src/utils/embeds.dart | 2 +- lib/src/utils/string.dart | 30 ++++----- lib/src/widgets/controller.dart | 16 ++--- lib/src/widgets/default_styles.dart | 16 ++--- lib/src/widgets/editor/editor.dart | 26 ++++---- lib/src/widgets/keyboard_listener.dart | 8 +-- lib/src/widgets/link.dart | 6 +- lib/src/widgets/proxy.dart | 27 ++++---- .../quill_single_child_scroll_view.dart | 5 +- lib/src/widgets/raw_editor/raw_editor.dart | 36 +++++------ ...editor_state_selection_delegate_mixin.dart | 6 +- ..._editor_state_text_input_client_mixin.dart | 2 +- .../widgets/style_widgets/bullet_point.dart | 4 +- .../widgets/style_widgets/checkbox_point.dart | 6 +- lib/src/widgets/text_block.dart | 13 ++-- lib/src/widgets/text_line.dart | 6 +- lib/src/widgets/text_selection.dart | 56 ++++++++--------- .../toolbar/buttons/arrow_indicated_list.dart | 6 +- lib/src/widgets/toolbar/buttons/color.dart | 5 +- .../widgets/toolbar/buttons/font_family.dart | 6 +- .../widgets/toolbar/buttons/font_size.dart | 6 +- lib/src/widgets/toolbar/buttons/history.dart | 6 +- lib/src/widgets/toolbar/buttons/indent.dart | 6 +- .../widgets/toolbar/buttons/link_style.dart | 8 +-- .../widgets/toolbar/buttons/link_style2.dart | 2 +- .../widgets/toolbar/buttons/quill_icon.dart | 4 +- .../toolbar/buttons/search/search_dialog.dart | 8 +-- .../toolbar/buttons/select_alignment.dart | 39 ++++++------ .../toolbar/buttons/select_header_style.dart | 10 +-- .../toolbar/buttons/toggle_check_list.dart | 6 +- .../widgets/toolbar/buttons/toggle_style.dart | 6 +- pubspec.yaml | 9 +-- test/widgets/controller_test.dart | 34 +++++----- 51 files changed, 301 insertions(+), 319 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a23ecd8a..430f82ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [8.1.11] +- Follow dart best practices by using `lints` and remove `pedantic` as well `platform` since they are not used + ## [8.1.10] - Secret for automated publishing to pub.dev. diff --git a/analysis_options.yaml b/analysis_options.yaml index 7749c861..f3e3dd31 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,5 @@ -include: package:pedantic/analysis_options.yaml +include: package:lints/recommended.yaml +# include: package:pedantic/analysis_options.yaml analyzer: errors: diff --git a/example/lib/pages/home_page.dart b/example/lib/pages/home_page.dart index 3411d5e7..288e9595 100644 --- a/example/lib/pages/home_page.dart +++ b/example/lib/pages/home_page.dart @@ -166,7 +166,7 @@ class _HomePageState extends State { extentOffset: offset + length, ); - controller.updateSelection(selection, ChangeSource.REMOTE); + controller.updateSelection(selection, ChangeSource.remote); // _selectionType = _SelectionType.line; @@ -539,7 +539,7 @@ class _HomePageState extends State { TextSelection.collapsed( offset: controller.selection.extentOffset + 1, ), - ChangeSource.LOCAL, + ChangeSource.local, ); controller.document.insert( @@ -551,7 +551,7 @@ class _HomePageState extends State { TextSelection.collapsed( offset: controller.selection.extentOffset + 1, ), - ChangeSource.LOCAL, + ChangeSource.local, ); controller.document.insert(controller.selection.extentOffset, ' '); @@ -559,7 +559,7 @@ class _HomePageState extends State { TextSelection.collapsed( offset: controller.selection.extentOffset + 1, ), - ChangeSource.LOCAL, + ChangeSource.local, ); controller.document.insert(controller.selection.extentOffset, '\n'); @@ -567,7 +567,7 @@ class _HomePageState extends State { TextSelection.collapsed( offset: controller.selection.extentOffset + 1, ), - ChangeSource.LOCAL, + ChangeSource.local, ); } } diff --git a/flutter_quill_extensions/analysis_options.yaml b/flutter_quill_extensions/analysis_options.yaml index 7749c861..8f1b96e4 100644 --- a/flutter_quill_extensions/analysis_options.yaml +++ b/flutter_quill_extensions/analysis_options.yaml @@ -1,4 +1,4 @@ -include: package:pedantic/analysis_options.yaml +include: package:lints/recommended.yaml analyzer: errors: diff --git a/flutter_quill_extensions/pubspec.yaml b/flutter_quill_extensions/pubspec.yaml index b90ceb10..66fd0b4b 100644 --- a/flutter_quill_extensions/pubspec.yaml +++ b/flutter_quill_extensions/pubspec.yaml @@ -49,7 +49,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^3.0.0 + flutter_lints: ^3.0.1 flutter: uses-material-design: true \ No newline at end of file diff --git a/lib/src/models/documents/attribute.dart b/lib/src/models/documents/attribute.dart index 91e6c89e..7797b2e6 100644 --- a/lib/src/models/documents/attribute.dart +++ b/lib/src/models/documents/attribute.dart @@ -4,10 +4,10 @@ import 'package:equatable/equatable.dart'; import 'package:quiver/core.dart'; enum AttributeScope { - INLINE, // refer to https://quilljs.com/docs/formats/#inline - BLOCK, // refer to https://quilljs.com/docs/formats/#block - EMBEDS, // refer to https://quilljs.com/docs/formats/#embeds - IGNORE, // attributes that can be ignored + inline, // refer to https://quilljs.com/docs/formats/#inline + block, // refer to https://quilljs.com/docs/formats/#block + embeds, // refer to https://quilljs.com/docs/formats/#embeds + ignore, // attributes that can be ignored } class Attribute extends Equatable { @@ -227,7 +227,7 @@ class Attribute extends Equatable { return IndentAttribute(level: level); } - bool get isInline => scope == AttributeScope.INLINE; + bool get isInline => scope == AttributeScope.inline; bool get isBlockExceptHeader => blockKeysExceptHeader.contains(key); @@ -283,110 +283,110 @@ class Attribute extends Equatable { } class BoldAttribute extends Attribute { - const BoldAttribute() : super('bold', AttributeScope.INLINE, true); + const BoldAttribute() : super('bold', AttributeScope.inline, true); } class ItalicAttribute extends Attribute { - const ItalicAttribute() : super('italic', AttributeScope.INLINE, true); + const ItalicAttribute() : super('italic', AttributeScope.inline, true); } class SmallAttribute extends Attribute { - const SmallAttribute() : super('small', AttributeScope.INLINE, true); + const SmallAttribute() : super('small', AttributeScope.inline, true); } class UnderlineAttribute extends Attribute { - const UnderlineAttribute() : super('underline', AttributeScope.INLINE, true); + const UnderlineAttribute() : super('underline', AttributeScope.inline, true); } class StrikeThroughAttribute extends Attribute { - const StrikeThroughAttribute() : super('strike', AttributeScope.INLINE, true); + const StrikeThroughAttribute() : super('strike', AttributeScope.inline, true); } class InlineCodeAttribute extends Attribute { - const InlineCodeAttribute() : super('code', AttributeScope.INLINE, true); + const InlineCodeAttribute() : super('code', AttributeScope.inline, true); } class FontAttribute extends Attribute { - const FontAttribute(String? val) : super('font', AttributeScope.INLINE, val); + const FontAttribute(String? val) : super('font', AttributeScope.inline, val); } class SizeAttribute extends Attribute { - const SizeAttribute(String? val) : super('size', AttributeScope.INLINE, val); + const SizeAttribute(String? val) : super('size', AttributeScope.inline, val); } class LinkAttribute extends Attribute { - const LinkAttribute(String? val) : super('link', AttributeScope.INLINE, val); + const LinkAttribute(String? val) : super('link', AttributeScope.inline, val); } class ColorAttribute extends Attribute { const ColorAttribute(String? val) - : super('color', AttributeScope.INLINE, val); + : super('color', AttributeScope.inline, val); } class BackgroundAttribute extends Attribute { const BackgroundAttribute(String? val) - : super('background', AttributeScope.INLINE, val); + : super('background', AttributeScope.inline, val); } /// This is custom attribute for hint class PlaceholderAttribute extends Attribute { const PlaceholderAttribute() - : super('placeholder', AttributeScope.INLINE, true); + : super('placeholder', AttributeScope.inline, true); } class HeaderAttribute extends Attribute { const HeaderAttribute({int? level}) - : super('header', AttributeScope.BLOCK, level); + : super('header', AttributeScope.block, level); } class IndentAttribute extends Attribute { const IndentAttribute({int? level}) - : super('indent', AttributeScope.BLOCK, level); + : super('indent', AttributeScope.block, level); } class AlignAttribute extends Attribute { - const AlignAttribute(String? val) : super('align', AttributeScope.BLOCK, val); + const AlignAttribute(String? val) : super('align', AttributeScope.block, val); } class ListAttribute extends Attribute { - const ListAttribute(String? val) : super('list', AttributeScope.BLOCK, val); + const ListAttribute(String? val) : super('list', AttributeScope.block, val); } class CodeBlockAttribute extends Attribute { - const CodeBlockAttribute() : super('code-block', AttributeScope.BLOCK, true); + const CodeBlockAttribute() : super('code-block', AttributeScope.block, true); } class BlockQuoteAttribute extends Attribute { - const BlockQuoteAttribute() : super('blockquote', AttributeScope.BLOCK, true); + const BlockQuoteAttribute() : super('blockquote', AttributeScope.block, true); } class DirectionAttribute extends Attribute { const DirectionAttribute(String? val) - : super('direction', AttributeScope.BLOCK, val); + : super('direction', AttributeScope.block, val); } class WidthAttribute extends Attribute { const WidthAttribute(String? val) - : super('width', AttributeScope.IGNORE, val); + : super('width', AttributeScope.ignore, val); } class HeightAttribute extends Attribute { const HeightAttribute(String? val) - : super('height', AttributeScope.IGNORE, val); + : super('height', AttributeScope.ignore, val); } class StyleAttribute extends Attribute { const StyleAttribute(String? val) - : super('style', AttributeScope.IGNORE, val); + : super('style', AttributeScope.ignore, val); } class TokenAttribute extends Attribute { - const TokenAttribute(String val) : super('token', AttributeScope.IGNORE, val); + const TokenAttribute(String val) : super('token', AttributeScope.ignore, val); } class ScriptAttribute extends Attribute { ScriptAttribute(ScriptAttributes? val) - : super('script', AttributeScope.INLINE, val?.value); + : super('script', AttributeScope.inline, val?.value); } enum ScriptAttributes { @@ -400,10 +400,10 @@ enum ScriptAttributes { class ImageAttribute extends Attribute { const ImageAttribute(String? url) - : super('image', AttributeScope.EMBEDS, url); + : super('image', AttributeScope.embeds, url); } class VideoAttribute extends Attribute { const VideoAttribute(String? url) - : super('video', AttributeScope.EMBEDS, url); + : super('video', AttributeScope.embeds, url); } diff --git a/lib/src/models/documents/document.dart b/lib/src/models/documents/document.dart index 55617865..9b8c21fd 100644 --- a/lib/src/models/documents/document.dart +++ b/lib/src/models/documents/document.dart @@ -78,9 +78,9 @@ class Document { return Delta(); } - final delta = _rules.apply(RuleType.INSERT, this, index, + final delta = _rules.apply(RuleType.insert, this, index, data: data, len: replaceLength); - compose(delta, ChangeSource.LOCAL); + compose(delta, ChangeSource.local); return delta; } @@ -92,9 +92,9 @@ class Document { /// Returns an instance of [Delta] actually composed into this document. Delta delete(int index, int len) { assert(index >= 0 && len > 0); - final delta = _rules.apply(RuleType.DELETE, this, index, len: len); + final delta = _rules.apply(RuleType.delete, this, index, len: len); if (delta.isNotEmpty) { - compose(delta, ChangeSource.LOCAL); + compose(delta, ChangeSource.local); } return delta; } @@ -142,10 +142,10 @@ class Document { var delta = Delta(); - final formatDelta = _rules.apply(RuleType.FORMAT, this, index, + final formatDelta = _rules.apply(RuleType.format, this, index, len: len, attribute: attribute); if (formatDelta.isNotEmpty) { - compose(formatDelta, ChangeSource.LOCAL); + compose(formatDelta, ChangeSource.local); delta = delta.compose(formatDelta); } @@ -445,8 +445,8 @@ class Document { /// Source of a [Change]. enum ChangeSource { /// Change originated from a local action. Typically triggered by user. - LOCAL, + local, /// Change originated from a remote action. - REMOTE, + remote, } diff --git a/lib/src/models/documents/history.dart b/lib/src/models/documents/history.dart index fa87700c..aa1ae769 100644 --- a/lib/src/models/documents/history.dart +++ b/lib/src/models/documents/history.dart @@ -34,7 +34,7 @@ class History { void handleDocChange(DocChange docChange) { if (ignoreChange) return; - if (!userOnly || docChange.source == ChangeSource.LOCAL) { + if (!userOnly || docChange.source == ChangeSource.local) { record(docChange.change, docChange.before); } else { transform(docChange.change); @@ -105,7 +105,7 @@ class History { dest.add(inverseDelta); lastRecorded = 0; ignoreChange = true; - doc.compose(delta, ChangeSource.LOCAL); + doc.compose(delta, ChangeSource.local); ignoreChange = false; return HistoryChanged(true, len); } diff --git a/lib/src/models/documents/nodes/container.dart b/lib/src/models/documents/nodes/container.dart index 47bc37e4..605e472e 100644 --- a/lib/src/models/documents/nodes/container.dart +++ b/lib/src/models/documents/nodes/container.dart @@ -137,17 +137,17 @@ abstract base class Container extends Node { } @override - void retain(int index, int? length, Style? attributes) { + void retain(int index, int? len, Style? style) { assert(isNotEmpty); final child = queryChild(index, false); - child.node!.retain(child.offset, length, attributes); + child.node!.retain(child.offset, len, style); } @override - void delete(int index, int? length) { + void delete(int index, int? len) { assert(isNotEmpty); final child = queryChild(index, false); - child.node!.delete(child.offset, length); + child.node!.delete(child.offset, len); } @override diff --git a/lib/src/models/documents/nodes/embeddable.dart b/lib/src/models/documents/nodes/embeddable.dart index b2db0abc..1db18da8 100644 --- a/lib/src/models/documents/nodes/embeddable.dart +++ b/lib/src/models/documents/nodes/embeddable.dart @@ -30,7 +30,7 @@ class Embeddable { /// the document model itself does not make any assumptions about the types /// of embedded objects and allows users to define their own types. class BlockEmbed extends Embeddable { - const BlockEmbed(String type, String data) : super(type, data); + const BlockEmbed(super.type, String super.data); static const String imageType = 'image'; static BlockEmbed image(String imageUrl) => BlockEmbed(imageType, imageUrl); @@ -47,7 +47,7 @@ class BlockEmbed extends Embeddable { } class CustomBlockEmbed extends BlockEmbed { - const CustomBlockEmbed(String type, String data) : super(type, data); + const CustomBlockEmbed(super.type, super.data); String toJsonString() => jsonEncode(toJson()); diff --git a/lib/src/models/documents/nodes/leaf.dart b/lib/src/models/documents/nodes/leaf.dart index 8ae3be36..4f1fd3b0 100644 --- a/lib/src/models/documents/nodes/leaf.dart +++ b/lib/src/models/documents/nodes/leaf.dart @@ -217,9 +217,9 @@ abstract base class Leaf extends Node { /// conflict with the one from the widgets, material or cupertino library /// base class QuillText extends Leaf { - QuillText([String text = '']) + QuillText([String super.text = '']) : assert(!text.contains('\n')), - super.val(text); + super.val(); @override Node newInstance() => QuillText(value); @@ -250,7 +250,7 @@ base class QuillText extends Leaf { /// applying "bold" style to an image gives no effect, while adding a "link" to /// an image actually makes the image react to user's action. base class Embed extends Leaf { - Embed(Embeddable data) : super.val(data); + Embed(Embeddable super.data) : super.val(); // Refer to https://www.fileformat.info/info/unicode/char/fffc/index.htm static const kObjectReplacementCharacter = '\uFFFC'; diff --git a/lib/src/models/documents/nodes/line.dart b/lib/src/models/documents/nodes/line.dart index 4a0c8c71..e11f095c 100644 --- a/lib/src/models/documents/nodes/line.dart +++ b/lib/src/models/documents/nodes/line.dart @@ -136,15 +136,15 @@ base class Line extends Container { if (isLineFormat) { assert( style.values.every((attr) => - attr.scope == AttributeScope.BLOCK || - attr.scope == AttributeScope.IGNORE), + attr.scope == AttributeScope.block || + attr.scope == AttributeScope.ignore), 'It is not allowed to apply inline attributes to line itself.'); _format(style); } else { // Otherwise forward to children as it's an inline format update. assert(style.values.every((attr) => - attr.scope == AttributeScope.INLINE || - attr.scope == AttributeScope.IGNORE)); + attr.scope == AttributeScope.inline || + attr.scope == AttributeScope.ignore)); assert(index + local != thisLength); super.retain(index, local, style); } @@ -351,7 +351,7 @@ base class Line extends Container { var result = const Style(); final excluded = {}; - void _handle(Style style) { + void handle(Style style) { for (final attr in result.values) { if (!style.containsKey(attr.key) || (style.attributes[attr.key] != attr.value)) { @@ -368,7 +368,7 @@ base class Line extends Container { var pos = node.length - data.offset; while (!node!.isLast && pos < local) { node = node.next as Leaf; - _handle(node.style); + handle(node.style); pos += node.length; } } @@ -382,7 +382,7 @@ base class Line extends Container { final remaining = len - local; if (remaining > 0 && nextLine != null) { final rest = nextLine!.collectStyle(0, remaining); - _handle(rest); + handle(rest); } return result; @@ -521,35 +521,35 @@ base class Line extends Container { } int _getPlainText(int offset, int len, StringBuffer plainText) { - var _len = len; + var len0 = len; final data = queryChild(offset, false); var node = data.node as Leaf?; - while (_len > 0) { + while (len0 > 0) { if (node == null) { // blank line plainText.write('\n'); - _len -= 1; + len0 -= 1; } else { - _len = _getNodeText(node, plainText, offset - node.offset, _len); + len0 = _getNodeText(node, plainText, offset - node.offset, len0); - while (!node!.isLast && _len > 0) { + while (!node!.isLast && len0 > 0) { node = node.next as Leaf; - _len = _getNodeText(node, plainText, 0, _len); + len0 = _getNodeText(node, plainText, 0, len0); } - if (_len > 0) { + if (len0 > 0) { // end of this line plainText.write('\n'); - _len -= 1; + len0 -= 1; } } - if (_len > 0 && nextLine != null) { - _len = nextLine!._getPlainText(0, _len, plainText); + if (len0 > 0 && nextLine != null) { + len0 = nextLine!._getPlainText(0, len0, plainText); } } - return _len; + return len0; } } diff --git a/lib/src/models/documents/style.dart b/lib/src/models/documents/style.dart index d3e1247a..589bfc15 100644 --- a/lib/src/models/documents/style.dart +++ b/lib/src/models/documents/style.dart @@ -21,7 +21,7 @@ class Style { final result = attributes.map((key, dynamic value) { final attr = Attribute.fromKeyValue(key, value); return MapEntry( - key, attr ?? Attribute(key, AttributeScope.IGNORE, value)); + key, attr ?? Attribute(key, AttributeScope.ignore, value)); }); return Style.attr(result); } @@ -45,10 +45,10 @@ class Style { bool get isInline => isNotEmpty && values.every((item) => item.isInline); bool get isBlock => - isNotEmpty && values.every((item) => item.scope == AttributeScope.BLOCK); + isNotEmpty && values.every((item) => item.scope == AttributeScope.block); bool get isIgnored => - isNotEmpty && values.every((item) => item.scope == AttributeScope.IGNORE); + isNotEmpty && values.every((item) => item.scope == AttributeScope.ignore); Attribute get single => _attributes.values.single; diff --git a/lib/src/models/quill_delta.dart b/lib/src/models/quill_delta.dart index a9babf60..196651e9 100644 --- a/lib/src/models/quill_delta.dart +++ b/lib/src/models/quill_delta.dart @@ -1,4 +1,6 @@ /// Implementation of Quill Delta format in Dart. +library; + import 'dart:math' as math; import 'package:collection/collection.dart'; @@ -262,11 +264,11 @@ class Delta { b ??= const {}; final attributes = {}; - (a.keys.toList()..addAll(b.keys)).forEach((key) { - if (a![key] != b![key]) { + for (final key in (a.keys.toList()..addAll(b.keys))) { + if (a[key] != b[key]) { attributes[key] = b.containsKey(key) ? b[key] : null; } - }); + } return attributes.keys.isNotEmpty ? attributes : null; } @@ -514,7 +516,7 @@ class Delta { final thisIter = DeltaIterator(this); final otherIter = DeltaIterator(other); - diffResult.forEach((component) { + for (final component in diffResult) { var length = component.text.length; while (length > 0) { var opLength = 0; @@ -549,7 +551,7 @@ class Delta { } length -= opLength; } - }); + } return retDelta..trim(); } @@ -787,9 +789,9 @@ class DeltaIterator { final op = delta.elementAt(_index); final opKey = op.key; final opAttributes = op.attributes; - final _currentOffset = _offset; - final actualLength = math.min(op.length! - _currentOffset, length); - if (actualLength == op.length! - _currentOffset) { + final currentOffset = _offset; + final actualLength = math.min(op.length! - currentOffset, length); + if (actualLength == op.length! - currentOffset) { _index++; _offset = 0; } else { @@ -797,7 +799,7 @@ class DeltaIterator { } final opData = op.isInsert && op.data is String ? (op.data as String) - .substring(_currentOffset, _currentOffset + actualLength) + .substring(currentOffset, currentOffset + actualLength) : op.data; final opIsNotEmpty = opData is String ? opData.isNotEmpty : true; // embeds are never empty diff --git a/lib/src/models/rules/delete.dart b/lib/src/models/rules/delete.dart index fd547825..b4555320 100644 --- a/lib/src/models/rules/delete.dart +++ b/lib/src/models/rules/delete.dart @@ -8,7 +8,7 @@ abstract class DeleteRule extends Rule { const DeleteRule(); @override - RuleType get type => RuleType.DELETE; + RuleType get type => RuleType.delete; @override void validateArgs(int? len, Object? data, Attribute? attribute) { diff --git a/lib/src/models/rules/format.dart b/lib/src/models/rules/format.dart index a57bac7a..7dea5e04 100644 --- a/lib/src/models/rules/format.dart +++ b/lib/src/models/rules/format.dart @@ -7,7 +7,7 @@ abstract class FormatRule extends Rule { const FormatRule(); @override - RuleType get type => RuleType.FORMAT; + RuleType get type => RuleType.format; @override void validateArgs(int? len, Object? data, Attribute? attribute) { @@ -30,7 +30,7 @@ class ResolveLineFormatRule extends FormatRule { Object? data, Attribute? attribute, }) { - if (attribute!.scope != AttributeScope.BLOCK) { + if (attribute!.scope != AttributeScope.block) { return null; } @@ -159,7 +159,7 @@ class ResolveInlineFormatRule extends FormatRule { Object? data, Attribute? attribute, }) { - if (attribute!.scope != AttributeScope.INLINE) { + if (attribute!.scope != AttributeScope.inline) { return null; } diff --git a/lib/src/models/rules/insert.dart b/lib/src/models/rules/insert.dart index 8f1c1dea..b4331d8f 100644 --- a/lib/src/models/rules/insert.dart +++ b/lib/src/models/rules/insert.dart @@ -10,7 +10,7 @@ abstract class InsertRule extends Rule { const InsertRule(); @override - RuleType get type => RuleType.INSERT; + RuleType get type => RuleType.insert; @override void validateArgs(int? len, Object? data, Attribute? attribute) { diff --git a/lib/src/models/rules/rule.dart b/lib/src/models/rules/rule.dart index 45b8bdf8..7f2c26cd 100644 --- a/lib/src/models/rules/rule.dart +++ b/lib/src/models/rules/rule.dart @@ -5,7 +5,7 @@ import 'delete.dart'; import 'format.dart'; import 'insert.dart'; -enum RuleType { INSERT, DELETE, FORMAT } +enum RuleType { insert, delete, format } abstract class Rule { const Rule(); diff --git a/lib/src/utils/embeds.dart b/lib/src/utils/embeds.dart index db693ba8..9ab16b65 100644 --- a/lib/src/utils/embeds.dart +++ b/lib/src/utils/embeds.dart @@ -7,7 +7,7 @@ import '../widgets/controller.dart'; OffsetValue getEmbedNode(QuillController controller, int offset) { var offset = controller.selection.start; var embedNode = controller.queryNode(offset); - if (embedNode == null || !(embedNode is Embed)) { + if (embedNode == null || embedNode is! Embed) { offset = max(0, offset - 1); embedNode = controller.queryNode(offset); } diff --git a/lib/src/utils/string.dart b/lib/src/utils/string.dart index 3de84e65..fe0207de 100644 --- a/lib/src/utils/string.dart +++ b/lib/src/utils/string.dart @@ -6,13 +6,13 @@ Map parseKeyValuePairs(String s, Set targetKeys) { final result = {}; final pairs = s.split(';'); for (final pair in pairs) { - final _index = pair.indexOf(':'); - if (_index < 0) { + final index = pair.indexOf(':'); + if (index < 0) { continue; } - final _key = pair.substring(0, _index).trim(); - if (targetKeys.contains(_key)) { - result[_key] = pair.substring(_index + 1).trim(); + final key = pair.substring(0, index).trim(); + if (targetKeys.contains(key)) { + result[key] = pair.substring(index + 1).trim(); } } @@ -28,12 +28,12 @@ String replaceStyleStringWithSize( final result = {}; final pairs = s.split(';'); for (final pair in pairs) { - final _index = pair.indexOf(':'); - if (_index < 0) { + final index = pair.indexOf(':'); + if (index < 0) { continue; } - final _key = pair.substring(0, _index).trim(); - result[_key] = pair.substring(_index + 1).trim(); + final key = pair.substring(0, index).trim(); + result[key] = pair.substring(index + 1).trim(); } if (isMobile) { @@ -55,12 +55,12 @@ String replaceStyleStringWithSize( } Alignment getAlignment(String? s) { - const _defaultAlignment = Alignment.center; + const defaultAlignment = Alignment.center; if (s == null) { - return _defaultAlignment; + return defaultAlignment; } - final _index = [ + final index = [ 'topLeft', 'topCenter', 'topRight', @@ -71,8 +71,8 @@ Alignment getAlignment(String? s) { 'bottomCenter', 'bottomRight' ].indexOf(s); - if (_index < 0) { - return _defaultAlignment; + if (index < 0) { + return defaultAlignment; } return [ @@ -85,5 +85,5 @@ Alignment getAlignment(String? s) { Alignment.bottomLeft, Alignment.bottomCenter, Alignment.bottomRight - ][_index]; + ][index]; } diff --git a/lib/src/widgets/controller.dart b/lib/src/widgets/controller.dart index fbfc77f0..b48ab9eb 100644 --- a/lib/src/widgets/controller.dart +++ b/lib/src/widgets/controller.dart @@ -202,7 +202,7 @@ class QuillController extends ChangeNotifier { // TextSelection.collapsed(offset: document.length), ChangeSource.LOCAL); updateSelection( TextSelection.collapsed(offset: selection.baseOffset + len), - ChangeSource.LOCAL); + ChangeSource.local); } else { // no need to move cursor notifyListeners(); @@ -261,13 +261,13 @@ class QuillController extends ChangeNotifier { final retainDelta = Delta() ..retain(index) ..retain(data is String ? data.length : 1, toggledStyle.toJson()); - document.compose(retainDelta, ChangeSource.LOCAL); + document.compose(retainDelta, ChangeSource.local); } } if (textSelection != null) { if (delta == null || delta.isEmpty) { - _updateSelection(textSelection, ChangeSource.LOCAL); + _updateSelection(textSelection, ChangeSource.local); } else { final user = Delta() ..retain(index) @@ -279,7 +279,7 @@ class QuillController extends ChangeNotifier { baseOffset: textSelection.baseOffset + positionDelta, extentOffset: textSelection.extentOffset + positionDelta, ), - ChangeSource.LOCAL, + ChangeSource.local, ); } } @@ -322,7 +322,7 @@ class QuillController extends ChangeNotifier { baseOffset: change.transformPosition(selection.baseOffset), extentOffset: change.transformPosition(selection.extentOffset)); if (selection != adjustedSelection) { - _updateSelection(adjustedSelection, ChangeSource.LOCAL); + _updateSelection(adjustedSelection, ChangeSource.local); } notifyListeners(); } @@ -334,21 +334,21 @@ class QuillController extends ChangeNotifier { void moveCursorToStart() { updateSelection( const TextSelection.collapsed(offset: 0), - ChangeSource.LOCAL, + ChangeSource.local, ); } void moveCursorToPosition(int position) { updateSelection( TextSelection.collapsed(offset: position), - ChangeSource.LOCAL, + ChangeSource.local, ); } void moveCursorToEnd() { updateSelection( TextSelection.collapsed(offset: plainTextEditingValue.text.length), - ChangeSource.LOCAL, + ChangeSource.local, ); } diff --git a/lib/src/widgets/default_styles.dart b/lib/src/widgets/default_styles.dart index dded6d08..6af846eb 100644 --- a/lib/src/widgets/default_styles.dart +++ b/lib/src/widgets/default_styles.dart @@ -11,9 +11,9 @@ import 'style_widgets/checkbox_point.dart'; class QuillStyles extends InheritedWidget { const QuillStyles({ required this.data, - required Widget child, - Key? key, - }) : super(key: key, child: child); + required super.child, + super.key, + }); final DefaultStyles data; @@ -128,12 +128,12 @@ class InlineCodeStyle { @immutable class DefaultListBlockStyle extends DefaultTextBlockStyle { const DefaultListBlockStyle( - TextStyle style, - VerticalSpacing verticalSpacing, - VerticalSpacing lineSpacing, - BoxDecoration? decoration, + super.style, + super.verticalSpacing, + super.lineSpacing, + super.decoration, this.checkboxUIBuilder, - ) : super(style, verticalSpacing, lineSpacing, decoration); + ); final QuillCheckboxBuilder? checkboxUIBuilder; } diff --git a/lib/src/widgets/editor/editor.dart b/lib/src/widgets/editor/editor.dart index 3c25cdb4..258f32c1 100644 --- a/lib/src/widgets/editor/editor.dart +++ b/lib/src/widgets/editor/editor.dart @@ -402,8 +402,8 @@ class _QuillEditorSelectionGestureDetectorBuilder return; } - final _platform = Theme.of(_state.context).platform; - if (isAppleOS(_platform)) { + final platform = Theme.of(_state.context).platform; + if (isAppleOS(platform)) { renderEditor!.selectPositionAt( from: details.globalPosition, cause: SelectionChangedCause.longPress, @@ -432,7 +432,7 @@ class _QuillEditorSelectionGestureDetectorBuilder if (segmentLeaf == null && line.length == 1) { editor!.widget.controller.updateSelection( TextSelection.collapsed(offset: pos.offset), - ChangeSource.LOCAL, + ChangeSource.local, ); return true; } @@ -475,8 +475,8 @@ class _QuillEditorSelectionGestureDetectorBuilder try { if (delegate.selectionEnabled && !_isPositionSelected(details)) { - final _platform = Theme.of(_state.context).platform; - if (isAppleOS(_platform) || isDesktop()) { + final platform = Theme.of(_state.context).platform; + if (isAppleOS(platform) || isDesktop()) { // added isDesktop() to enable extend selection in Windows platform switch (details.kind) { case PointerDeviceKind.mouse: @@ -539,8 +539,8 @@ class _QuillEditorSelectionGestureDetectorBuilder } if (delegate.selectionEnabled) { - final _platform = Theme.of(_state.context).platform; - if (isAppleOS(_platform)) { + final platform = Theme.of(_state.context).platform; + if (isAppleOS(platform)) { renderEditor!.selectPositionAt( from: details.globalPosition, cause: SelectionChangedCause.longPress, @@ -608,20 +608,20 @@ class RenderEditor extends RenderEditableContainerBox implements RenderAbstractEditor { RenderEditor({ required this.document, - required TextDirection textDirection, + required super.textDirection, required bool hasFocus, required this.selection, required this.scrollable, required LayerLink startHandleLayerLink, required LayerLink endHandleLayerLink, - required EdgeInsetsGeometry padding, + required super.padding, required CursorCont cursorController, required this.onSelectionChanged, required this.onSelectionCompleted, - required double scrollBottomInset, + required super.scrollBottomInset, required this.floatingCursorDisabled, ViewportOffset? offset, - List? children, + super.children, EdgeInsets floatingCursorAddedMargin = const EdgeInsets.fromLTRB(4, 4, 4, 5), double? maxContentWidth, @@ -632,11 +632,7 @@ class RenderEditor extends RenderEditableContainerBox _cursorController = cursorController, _maxContentWidth = maxContentWidth, super( - children: children, container: document.root, - textDirection: textDirection, - scrollBottomInset: scrollBottomInset, - padding: padding, ); final CursorCont _cursorController; diff --git a/lib/src/widgets/keyboard_listener.dart b/lib/src/widgets/keyboard_listener.dart index ee1e3d11..cba72b4f 100644 --- a/lib/src/widgets/keyboard_listener.dart +++ b/lib/src/widgets/keyboard_listener.dart @@ -31,8 +31,7 @@ class QuillPressedKeys extends ChangeNotifier { } class QuillKeyboardListener extends StatefulWidget { - const QuillKeyboardListener({required this.child, Key? key}) - : super(key: key); + const QuillKeyboardListener({required this.child, super.key}); final Widget child; @@ -77,9 +76,8 @@ class QuillKeyboardListenerState extends State { class _QuillPressedKeysAccess extends InheritedWidget { const _QuillPressedKeysAccess({ required this.pressedKeys, - required Widget child, - Key? key, - }) : super(key: key, child: child); + required super.child, + }); final QuillPressedKeys pressedKeys; diff --git a/lib/src/widgets/link.dart b/lib/src/widgets/link.dart index 345a0027..1489ba26 100644 --- a/lib/src/widgets/link.dart +++ b/lib/src/widgets/link.dart @@ -124,8 +124,7 @@ class _CupertinoAction extends StatelessWidget { required this.title, required this.icon, required this.onPressed, - Key? key, - }) : super(key: key); + }); final String title; final IconData icon; @@ -195,8 +194,7 @@ class _MaterialAction extends StatelessWidget { required this.title, required this.icon, required this.onPressed, - Key? key, - }) : super(key: key); + }); final String title; final IconData icon; diff --git a/lib/src/widgets/proxy.dart b/lib/src/widgets/proxy.dart index 2379c883..06f44191 100644 --- a/lib/src/widgets/proxy.dart +++ b/lib/src/widgets/proxy.dart @@ -7,11 +7,11 @@ import 'box.dart'; class BaselineProxy extends SingleChildRenderObjectWidget { const BaselineProxy({ - Key? key, - Widget? child, + super.key, + super.child, this.textStyle, this.padding, - }) : super(key: key, child: child); + }); final TextStyle? textStyle; final EdgeInsets? padding; @@ -36,15 +36,14 @@ class BaselineProxy extends SingleChildRenderObjectWidget { class RenderBaselineProxy extends RenderProxyBox { RenderBaselineProxy( - RenderParagraph? child, + RenderParagraph? super.child, TextStyle textStyle, EdgeInsets? padding, - ) : _prototypePainter = TextPainter( + ) : _prototypePainter = TextPainter( text: TextSpan(text: ' ', style: textStyle), textDirection: TextDirection.ltr, strutStyle: - StrutStyle.fromTextStyle(textStyle, forceStrutHeight: true)), - super(child); + StrutStyle.fromTextStyle(textStyle, forceStrutHeight: true)); final TextPainter _prototypePainter; @@ -87,7 +86,7 @@ class EmbedProxy extends SingleChildRenderObjectWidget { } class RenderEmbedProxy extends RenderProxyBox implements RenderContentProxyBox { - RenderEmbedProxy(RenderBox? child) : super(child); + RenderEmbedProxy(super.child); @override List getBoxesForSelection(TextSelection selection) { @@ -131,7 +130,7 @@ class RenderEmbedProxy extends RenderProxyBox implements RenderContentProxyBox { class RichTextProxy extends SingleChildRenderObjectWidget { /// Child argument should be an instance of RichText widget. const RichTextProxy( - {required RichText child, + {required RichText super.child, required this.textStyle, required this.textAlign, required this.textDirection, @@ -140,8 +139,7 @@ class RichTextProxy extends SingleChildRenderObjectWidget { this.textScaleFactor = 1.0, this.textWidthBasis = TextWidthBasis.parent, this.textHeightBehavior, - Key? key}) - : super(key: key, child: child); + super.key}); final TextStyle textStyle; final TextAlign textAlign; @@ -184,7 +182,7 @@ class RichTextProxy extends SingleChildRenderObjectWidget { class RenderParagraphProxy extends RenderProxyBox implements RenderContentProxyBox { RenderParagraphProxy( - RenderParagraph? child, + RenderParagraph? super.child, TextStyle textStyle, TextAlign textAlign, TextDirection textDirection, @@ -193,7 +191,7 @@ class RenderParagraphProxy extends RenderProxyBox Locale locale, TextWidthBasis textWidthBasis, TextHeightBehavior? textHeightBehavior, - ) : _prototypePainter = TextPainter( + ) : _prototypePainter = TextPainter( text: TextSpan(text: ' ', style: textStyle), textAlign: textAlign, textDirection: textDirection, @@ -201,8 +199,7 @@ class RenderParagraphProxy extends RenderProxyBox strutStyle: strutStyle, locale: locale, textWidthBasis: textWidthBasis, - textHeightBehavior: textHeightBehavior), - super(child); + textHeightBehavior: textHeightBehavior); final TextPainter _prototypePainter; diff --git a/lib/src/widgets/quill_single_child_scroll_view.dart b/lib/src/widgets/quill_single_child_scroll_view.dart index ba6c0371..80efbda7 100644 --- a/lib/src/widgets/quill_single_child_scroll_view.dart +++ b/lib/src/widgets/quill_single_child_scroll_view.dart @@ -77,9 +77,8 @@ class QuillSingleChildScrollView extends StatelessWidget { class _SingleChildViewport extends SingleChildRenderObjectWidget { const _SingleChildViewport({ required this.offset, - Key? key, - Widget? child, - }) : super(key: key, child: child); + super.child, + }); final ViewportOffset offset; diff --git a/lib/src/widgets/raw_editor/raw_editor.dart b/lib/src/widgets/raw_editor/raw_editor.dart index 28d6c342..fa2944a1 100644 --- a/lib/src/widgets/raw_editor/raw_editor.dart +++ b/lib/src/widgets/raw_editor/raw_editor.dart @@ -468,10 +468,10 @@ class RawEditorState extends EditorState assert(debugCheckHasMediaQuery(context)); super.build(context); - var _doc = controller.document; - if (_doc.isEmpty() && widget.placeholder != null) { + var doc = controller.document; + if (doc.isEmpty() && widget.placeholder != null) { final raw = widget.placeholder?.replaceAll(r'"', '\\"'); - _doc = Document.fromJson( + doc = Document.fromJson( jsonDecode( '[{"attributes":{"placeholder":true},"insert":"$raw\\n"}]', ), @@ -485,7 +485,7 @@ class RawEditorState extends EditorState cursor: SystemMouseCursors.text, child: _Editor( key: _editorKey, - document: _doc, + document: doc, selection: controller.selection, hasFocus: _hasFocus, scrollable: widget.scrollable, @@ -499,7 +499,7 @@ class RawEditorState extends EditorState padding: widget.padding, maxContentWidth: widget.maxContentWidth, floatingCursorDisabled: widget.floatingCursorDisabled, - children: _buildChildren(_doc, context), + children: _buildChildren(doc, context), ), ), ), @@ -527,7 +527,7 @@ class RawEditorState extends EditorState child: _Editor( key: _editorKey, offset: offset, - document: _doc, + document: doc, selection: controller.selection, hasFocus: _hasFocus, scrollable: widget.scrollable, @@ -541,7 +541,7 @@ class RawEditorState extends EditorState maxContentWidth: widget.maxContentWidth, cursorController: _cursorCont, floatingCursorDisabled: widget.floatingCursorDisabled, - children: _buildChildren(_doc, context), + children: _buildChildren(doc, context), ), ), ), @@ -853,7 +853,7 @@ class RawEditorState extends EditorState controller.selection.copyWith( baseOffset: selection.baseOffset + chars, extentOffset: selection.baseOffset + chars), - ChangeSource.LOCAL); + ChangeSource.local); } void _updateSelectionForKeyPhrase(String phrase, Attribute attribute) { @@ -871,7 +871,7 @@ class RawEditorState extends EditorState SelectionChangedCause cause, ) { final oldSelection = controller.selection; - controller.updateSelection(selection, ChangeSource.LOCAL); + controller.updateSelection(selection, ChangeSource.local); _selectionOverlay?.handlesVisible = _shouldShowSelectionHandles(); @@ -925,7 +925,7 @@ class RawEditorState extends EditorState controller ..ignoreFocusOnTextChange = false ..skipRequestKeyboard = !requestKeyboardFocusOnCheckListChanged - ..updateSelection(currentSelection, ChangeSource.LOCAL); + ..updateSelection(currentSelection, ChangeSource.local); }); } } @@ -1839,8 +1839,8 @@ class RawEditorState extends EditorState class _Editor extends MultiChildRenderObjectWidget { const _Editor({ - required Key key, - required List children, + required Key super.key, + required super.children, required this.document, required this.textDirection, required this.hasFocus, @@ -1856,7 +1856,7 @@ class _Editor extends MultiChildRenderObjectWidget { this.padding = EdgeInsets.zero, this.maxContentWidth, this.offset, - }) : super(key: key, children: children); + }); final ViewportOffset? offset; final Document document; @@ -2292,7 +2292,7 @@ class _UpdateTextSelectionAction final collapseSelection = intent.collapseSelection || !state.widget.selectionEnabled; // Collapse to the logical start/end. - TextSelection _collapse(TextSelection selection) { + TextSelection collapse(TextSelection selection) { assert(selection.isValid); assert(!selection.isCollapsed); return selection.copyWith( @@ -2306,7 +2306,7 @@ class _UpdateTextSelectionAction collapseSelection) { return Actions.invoke( context!, - UpdateSelectionIntent(state.textEditingValue, _collapse(selection), + UpdateSelectionIntent(state.textEditingValue, collapse(selection), SelectionChangedCause.keyboard), ); } @@ -2322,7 +2322,7 @@ class _UpdateTextSelectionAction return Actions.invoke( context!, UpdateSelectionIntent(state.textEditingValue, - _collapse(textBoundarySelection), SelectionChangedCause.keyboard), + collapse(textBoundarySelection), SelectionChangedCause.keyboard), ); } @@ -2682,9 +2682,9 @@ class _ApplyHeaderAction extends Action { @override void invoke(ApplyHeaderIntent intent, [BuildContext? context]) { - final _attribute = + final attribute = _getHeaderValue() == intent.header ? Attribute.header : intent.header; - state.controller.formatSelection(_attribute); + state.controller.formatSelection(attribute); } @override diff --git a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart b/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart index 603402fa..0ad2c1c7 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart @@ -24,7 +24,7 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState final diff = getDiff(oldText, newText, cursorPosition); if (diff.deleted == '' && diff.inserted == '') { // Only changing selection range - widget.controller.updateSelection(value.selection, ChangeSource.LOCAL); + widget.controller.updateSelection(value.selection, ChangeSource.local); return; } @@ -61,9 +61,9 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState final node = widget.controller.document.queryChild(local).node; if (node != null && pasteStyleAndEmbed[i].length == node.length - 1) { - style.values.forEach((attribute) { + for (final attribute in style.values) { widget.controller.document.format(local, 0, attribute); - }); + } } } } diff --git a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart index 2cd9ebf1..01411570 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart @@ -187,7 +187,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState final cursorPosition = value.selection.extentOffset; final diff = getDiff(oldText, text, cursorPosition); if (diff.deleted.isEmpty && diff.inserted.isEmpty) { - widget.controller.updateSelection(value.selection, ChangeSource.LOCAL); + widget.controller.updateSelection(value.selection, ChangeSource.local); } else { widget.controller.replaceText( diff.start, diff.deleted.length, diff.inserted, value.selection); diff --git a/lib/src/widgets/style_widgets/bullet_point.dart b/lib/src/widgets/style_widgets/bullet_point.dart index f760c992..1dd1b4cf 100644 --- a/lib/src/widgets/style_widgets/bullet_point.dart +++ b/lib/src/widgets/style_widgets/bullet_point.dart @@ -5,8 +5,8 @@ class QuillEditorBulletPoint extends StatelessWidget { required this.style, required this.width, this.padding = 0, - Key? key, - }) : super(key: key); + super.key, + }); final TextStyle style; final double width; diff --git a/lib/src/widgets/style_widgets/checkbox_point.dart b/lib/src/widgets/style_widgets/checkbox_point.dart index 4d87df16..509db66f 100644 --- a/lib/src/widgets/style_widgets/checkbox_point.dart +++ b/lib/src/widgets/style_widgets/checkbox_point.dart @@ -20,11 +20,11 @@ class QuillEditorCheckboxPoint extends StatefulWidget { final QuillCheckboxBuilder? uiBuilder; @override - _QuillEditorCheckboxPointState createState() => - _QuillEditorCheckboxPointState(); + QuillEditorCheckboxPointState createState() => + QuillEditorCheckboxPointState(); } -class _QuillEditorCheckboxPointState extends State { +class QuillEditorCheckboxPointState extends State { @override Widget build(BuildContext context) { final uiBuilder = widget.uiBuilder; diff --git a/lib/src/widgets/text_block.dart b/lib/src/widgets/text_block.dart index f99ccbb0..71494df0 100644 --- a/lib/src/widgets/text_block.dart +++ b/lib/src/widgets/text_block.dart @@ -351,21 +351,18 @@ class RenderEditableTextBlock extends RenderEditableContainerBox implements RenderEditableBox { RenderEditableTextBlock({ required Block block, - required TextDirection textDirection, + required super.textDirection, required EdgeInsetsGeometry padding, - required double scrollBottomInset, + required super.scrollBottomInset, required Decoration decoration, - List? children, + super.children, EdgeInsets contentPadding = EdgeInsets.zero, }) : _decoration = decoration, _configuration = ImageConfiguration(textDirection: textDirection), _savedPadding = padding, _contentPadding = contentPadding, super( - children: children, container: block, - textDirection: textDirection, - scrollBottomInset: scrollBottomInset, padding: padding.add(contentPadding), ); @@ -665,9 +662,7 @@ class _EditableBlock extends MultiChildRenderObjectWidget { required this.scrollBottomInset, required this.decoration, required this.contentPadding, - required List children, - Key? key}) - : super(key: key, children: children); + required super.children}); final Block block; final TextDirection textDirection; diff --git a/lib/src/widgets/text_line.dart b/lib/src/widgets/text_line.dart index 8aa88ccb..b482ed79 100644 --- a/lib/src/widgets/text_line.dart +++ b/lib/src/widgets/text_line.dart @@ -294,14 +294,14 @@ class _TextLineState extends State { if (widget.customStyleBuilder == null) { return textStyle; } - attributes.keys.forEach((key) { + for (final key in attributes.keys) { final attr = attributes[key]; if (attr != null) { /// Custom Attribute final customAttr = widget.customStyleBuilder!.call(attr); textStyle = textStyle.merge(customAttr); } - }); + } return textStyle; } @@ -1292,7 +1292,7 @@ class RenderEditableTextLine extends RenderEditableBox { } class _TextLineElement extends RenderObjectElement { - _TextLineElement(EditableTextLine line) : super(line); + _TextLineElement(EditableTextLine super.line); final Map _slotToChildren = {}; diff --git a/lib/src/widgets/text_selection.dart b/lib/src/widgets/text_selection.dart index a4285308..7d88d316 100644 --- a/lib/src/widgets/text_selection.dart +++ b/lib/src/widgets/text_selection.dart @@ -21,22 +21,17 @@ TextSelection localSelection(Node node, TextSelection selection, fromParent) { /// The text position that a give selection handle manipulates. Dragging the /// [start] handle always moves the [start]/[baseOffset] of the selection. -enum _TextSelectionHandlePosition { START, END } +enum _TextSelectionHandlePosition { start, end } /// internal use, used to get drag direction information class DragTextSelection extends TextSelection { const DragTextSelection({ - TextAffinity affinity = TextAffinity.downstream, - int baseOffset = 0, - int extentOffset = 0, - bool isDirectional = false, + super.affinity, + super.baseOffset = 0, + super.extentOffset = 0, + super.isDirectional, this.first = true, - }) : super( - baseOffset: baseOffset, - extentOffset: extentOffset, - affinity: affinity, - isDirectional: isDirectional, - ); + }); final bool first; @@ -236,7 +231,7 @@ class EditorTextSelectionOverlay { Widget _buildHandle( BuildContext context, _TextSelectionHandlePosition position) { if (_selection.isCollapsed && - position == _TextSelectionHandlePosition.END) { + position == _TextSelectionHandlePosition.end) { return Container(); } return Visibility( @@ -282,12 +277,12 @@ class EditorTextSelectionOverlay { TextSelection? newSelection, _TextSelectionHandlePosition position) { TextPosition textPosition; switch (position) { - case _TextSelectionHandlePosition.START: + case _TextSelectionHandlePosition.start: textPosition = newSelection != null ? newSelection.base : const TextPosition(offset: 0); break; - case _TextSelectionHandlePosition.END: + case _TextSelectionHandlePosition.end: textPosition = newSelection != null ? newSelection.extent : const TextPosition(offset: 0); @@ -302,7 +297,7 @@ class EditorTextSelectionOverlay { extentOffset: newSelection.extentOffset, affinity: newSelection.affinity, isDirectional: newSelection.isDirectional, - first: position == _TextSelectionHandlePosition.START, + first: position == _TextSelectionHandlePosition.start, ) : null; @@ -344,10 +339,10 @@ class EditorTextSelectionOverlay { _handles = [ OverlayEntry( builder: (context) => - _buildHandle(context, _TextSelectionHandlePosition.START)), + _buildHandle(context, _TextSelectionHandlePosition.start)), OverlayEntry( builder: (context) => - _buildHandle(context, _TextSelectionHandlePosition.END)), + _buildHandle(context, _TextSelectionHandlePosition.end)), ]; Overlay.of(context, rootOverlay: true, debugRequiredFor: debugRequiredFor) @@ -375,8 +370,7 @@ class _TextSelectionHandleOverlay extends StatefulWidget { required this.onSelectionHandleTapped, required this.selectionControls, this.dragStartBehavior = DragStartBehavior.start, - Key? key, - }) : super(key: key); + }); final TextSelection selection; final _TextSelectionHandlePosition position; @@ -394,9 +388,9 @@ class _TextSelectionHandleOverlay extends StatefulWidget { ValueListenable get _visibility { switch (position) { - case _TextSelectionHandlePosition.START: + case _TextSelectionHandlePosition.start: return renderObject.selectionStartInViewport; - case _TextSelectionHandlePosition.END: + case _TextSelectionHandlePosition.end: return renderObject.selectionEndInViewport; default: throw 'Invalid position'; @@ -449,7 +443,7 @@ class _TextSelectionHandleOverlayState } void _handleDragStart(DragStartDetails details) { - final textPosition = widget.position == _TextSelectionHandlePosition.START + final textPosition = widget.position == _TextSelectionHandlePosition.start ? widget.selection.base : widget.selection.extent; final lineHeight = widget.renderObject.preferredLineHeight(textPosition); @@ -470,7 +464,7 @@ class _TextSelectionHandleOverlayState widget.selection.extentOffset >= widget.selection.baseOffset; TextSelection newSelection; switch (widget.position) { - case _TextSelectionHandlePosition.START: + case _TextSelectionHandlePosition.start: newSelection = TextSelection( baseOffset: isNormalized ? position.offset : widget.selection.baseOffset, @@ -478,7 +472,7 @@ class _TextSelectionHandleOverlayState isNormalized ? widget.selection.extentOffset : position.offset, ); break; - case _TextSelectionHandlePosition.END: + case _TextSelectionHandlePosition.end: newSelection = TextSelection( baseOffset: isNormalized ? widget.selection.baseOffset : position.offset, @@ -507,7 +501,7 @@ class _TextSelectionHandleOverlayState TextSelectionHandleType? type; switch (widget.position) { - case _TextSelectionHandlePosition.START: + case _TextSelectionHandlePosition.start: layerLink = widget.startHandleLayerLink; type = _chooseType( widget.renderObject.textDirection, @@ -515,7 +509,7 @@ class _TextSelectionHandleOverlayState TextSelectionHandleType.right, ); break; - case _TextSelectionHandlePosition.END: + case _TextSelectionHandlePosition.end: // For collapsed selections, we shouldn't be building the [end] handle. assert(!widget.selection.isCollapsed); layerLink = widget.endHandleLayerLink; @@ -533,7 +527,7 @@ class _TextSelectionHandleOverlayState // May have to use getSelectionBoxes instead of preferredLineHeight. // or expose TextStyle on the render object and calculate // preferredLineHeight / style.height - final textPosition = widget.position == _TextSelectionHandlePosition.START + final textPosition = widget.position == _TextSelectionHandlePosition.start ? widget.selection.base : widget.selection.extent; final lineHeight = widget.renderObject.preferredLineHeight(textPosition); @@ -649,8 +643,8 @@ class EditorTextSelectionGestureDetector extends StatefulWidget { this.onDragSelectionEnd, this.behavior, this.detectWordBoundary = true, - Key? key, - }) : super(key: key); + super.key, + }); /// Called for every tap down including every tap down that's part of a /// double click or a long press, except touches that include enough movement @@ -1001,8 +995,8 @@ class _EditorTextSelectionGestureDetectorState // underlying input. class _TransparentTapGestureRecognizer extends TapGestureRecognizer { _TransparentTapGestureRecognizer({ - Object? debugOwner, - }) : super(debugOwner: debugOwner); + super.debugOwner, + }); @override void rejectGesture(int pointer) { diff --git a/lib/src/widgets/toolbar/buttons/arrow_indicated_list.dart b/lib/src/widgets/toolbar/buttons/arrow_indicated_list.dart index f90b9b4d..c8ccd1bc 100644 --- a/lib/src/widgets/toolbar/buttons/arrow_indicated_list.dart +++ b/lib/src/widgets/toolbar/buttons/arrow_indicated_list.dart @@ -17,11 +17,11 @@ class QuillToolbarArrowIndicatedButtonList extends StatefulWidget { final List buttons; @override - _QuillToolbarArrowIndicatedButtonListState createState() => - _QuillToolbarArrowIndicatedButtonListState(); + QuillToolbarArrowIndicatedButtonListState createState() => + QuillToolbarArrowIndicatedButtonListState(); } -class _QuillToolbarArrowIndicatedButtonListState +class QuillToolbarArrowIndicatedButtonListState extends State with WidgetsBindingObserver { final ScrollController _controller = ScrollController(); diff --git a/lib/src/widgets/toolbar/buttons/color.dart b/lib/src/widgets/toolbar/buttons/color.dart index 9a0f0789..83da1e06 100644 --- a/lib/src/widgets/toolbar/buttons/color.dart +++ b/lib/src/widgets/toolbar/buttons/color.dart @@ -28,11 +28,10 @@ class QuillToolbarColorButton extends StatefulWidget { final QuillToolbarColorButtonOptions options; @override - _QuillToolbarColorButtonState createState() => - _QuillToolbarColorButtonState(); + QuillToolbarColorButtonState createState() => QuillToolbarColorButtonState(); } -class _QuillToolbarColorButtonState extends State { +class QuillToolbarColorButtonState extends State { late bool _isToggledColor; late bool _isToggledBackground; late bool _isWhite; diff --git a/lib/src/widgets/toolbar/buttons/font_family.dart b/lib/src/widgets/toolbar/buttons/font_family.dart index a82424a1..163fb295 100644 --- a/lib/src/widgets/toolbar/buttons/font_family.dart +++ b/lib/src/widgets/toolbar/buttons/font_family.dart @@ -26,11 +26,11 @@ class QuillToolbarFontFamilyButton extends StatefulWidget { final QuillController controller; @override - _QuillToolbarFontFamilyButtonState createState() => - _QuillToolbarFontFamilyButtonState(); + QuillToolbarFontFamilyButtonState createState() => + QuillToolbarFontFamilyButtonState(); } -class _QuillToolbarFontFamilyButtonState +class QuillToolbarFontFamilyButtonState extends State { var _currentValue = ''; diff --git a/lib/src/widgets/toolbar/buttons/font_size.dart b/lib/src/widgets/toolbar/buttons/font_size.dart index 419ad46a..a6ddf7e8 100644 --- a/lib/src/widgets/toolbar/buttons/font_size.dart +++ b/lib/src/widgets/toolbar/buttons/font_size.dart @@ -21,11 +21,11 @@ class QuillToolbarFontSizeButton extends StatefulWidget { final QuillController controller; @override - _QuillToolbarFontSizeButtonState createState() => - _QuillToolbarFontSizeButtonState(); + QuillToolbarFontSizeButtonState createState() => + QuillToolbarFontSizeButtonState(); } -class _QuillToolbarFontSizeButtonState +class QuillToolbarFontSizeButtonState extends State { String _currentValue = ''; diff --git a/lib/src/widgets/toolbar/buttons/history.dart b/lib/src/widgets/toolbar/buttons/history.dart index 297b4b9f..5bae3bfd 100644 --- a/lib/src/widgets/toolbar/buttons/history.dart +++ b/lib/src/widgets/toolbar/buttons/history.dart @@ -16,11 +16,11 @@ class QuillToolbarHistoryButton extends StatefulWidget { final QuillController controller; @override - _QuillToolbarHistoryButtonState createState() => - _QuillToolbarHistoryButtonState(); + QuillToolbarHistoryButtonState createState() => + QuillToolbarHistoryButtonState(); } -class _QuillToolbarHistoryButtonState extends State { +class QuillToolbarHistoryButtonState extends State { late ThemeData theme; var _canPressed = false; diff --git a/lib/src/widgets/toolbar/buttons/indent.dart b/lib/src/widgets/toolbar/buttons/indent.dart index 8aad9671..2c8cdf94 100644 --- a/lib/src/widgets/toolbar/buttons/indent.dart +++ b/lib/src/widgets/toolbar/buttons/indent.dart @@ -24,11 +24,11 @@ class QuillToolbarIndentButton extends StatefulWidget { final QuillToolbarIndentButtonOptions options; @override - _QuillToolbarIndentButtonState createState() => - _QuillToolbarIndentButtonState(); + QuillToolbarIndentButtonState createState() => + QuillToolbarIndentButtonState(); } -class _QuillToolbarIndentButtonState extends State { +class QuillToolbarIndentButtonState extends State { QuillToolbarIndentButtonOptions get options { return widget.options; } diff --git a/lib/src/widgets/toolbar/buttons/link_style.dart b/lib/src/widgets/toolbar/buttons/link_style.dart index b7bf91c0..5234dbaf 100644 --- a/lib/src/widgets/toolbar/buttons/link_style.dart +++ b/lib/src/widgets/toolbar/buttons/link_style.dart @@ -22,11 +22,11 @@ class QuillToolbarLinkStyleButton extends StatefulWidget { final QuillToolbarLinkStyleButtonOptions options; @override - _QuillToolbarLinkStyleButtonState createState() => - _QuillToolbarLinkStyleButtonState(); + QuillToolbarLinkStyleButtonState createState() => + QuillToolbarLinkStyleButtonState(); } -class _QuillToolbarLinkStyleButtonState +class QuillToolbarLinkStyleButtonState extends State { void _didChangeSelection() { setState(() {}); @@ -161,7 +161,7 @@ class _QuillToolbarLinkStyleButtonState final link = _getLinkAttributeValue(); final index = controller.selection.start; - var text; + String? text; if (link != null) { // text should be the link's corresponding text, not selection final leaf = controller.document.querySegmentLeafNode(index).leaf; diff --git a/lib/src/widgets/toolbar/buttons/link_style2.dart b/lib/src/widgets/toolbar/buttons/link_style2.dart index 57e0bcf1..751c860b 100644 --- a/lib/src/widgets/toolbar/buttons/link_style2.dart +++ b/lib/src/widgets/toolbar/buttons/link_style2.dart @@ -448,7 +448,7 @@ class QuillTextLink { controller.getSelectionStyle().attributes[Attribute.link.key]?.value; final index = controller.selection.start; - var text; + String? text; if (link != null) { // text should be the link's corresponding text, not selection final leaf = controller.document.querySegmentLeafNode(index).leaf; diff --git a/lib/src/widgets/toolbar/buttons/quill_icon.dart b/lib/src/widgets/toolbar/buttons/quill_icon.dart index 0ac6e8f9..37e5b81a 100644 --- a/lib/src/widgets/toolbar/buttons/quill_icon.dart +++ b/lib/src/widgets/toolbar/buttons/quill_icon.dart @@ -13,8 +13,8 @@ class QuillToolbarIconButton extends StatelessWidget { this.highlightElevation = 1, this.borderRadius = 2, this.tooltip, - Key? key, - }) : super(key: key); + super.key, + }); final VoidCallback? onPressed; final VoidCallback? afterPressed; diff --git a/lib/src/widgets/toolbar/buttons/search/search_dialog.dart b/lib/src/widgets/toolbar/buttons/search/search_dialog.dart index dc279ab4..1ff4c856 100644 --- a/lib/src/widgets/toolbar/buttons/search/search_dialog.dart +++ b/lib/src/widgets/toolbar/buttons/search/search_dialog.dart @@ -52,11 +52,11 @@ class QuillToolbarSearchDialog extends StatefulWidget { final QuillToolbarSearchDialogChildBuilder? childBuilder; @override - _QuillToolbarSearchDialogState createState() => - _QuillToolbarSearchDialogState(); + QuillToolbarSearchDialogState createState() => + QuillToolbarSearchDialogState(); } -class _QuillToolbarSearchDialogState extends State { +class QuillToolbarSearchDialogState extends State { late String _text; late TextEditingController _controller; late List? _offsets; @@ -217,7 +217,7 @@ class _QuillToolbarSearchDialogState extends State { baseOffset: _offsets![_index], extentOffset: _offsets![_index] + _text.length, ), - ChangeSource.LOCAL, + ChangeSource.local, ); } diff --git a/lib/src/widgets/toolbar/buttons/select_alignment.dart b/lib/src/widgets/toolbar/buttons/select_alignment.dart index 9ee36622..fac78d85 100644 --- a/lib/src/widgets/toolbar/buttons/select_alignment.dart +++ b/lib/src/widgets/toolbar/buttons/select_alignment.dart @@ -32,11 +32,11 @@ class QuillToolbarSelectAlignmentButton extends StatefulWidget { final EdgeInsetsGeometry? padding; @override - _QuillToolbarSelectAlignmentButtonState createState() => - _QuillToolbarSelectAlignmentButtonState(); + QuillToolbarSelectAlignmentButtonState createState() => + QuillToolbarSelectAlignmentButtonState(); } -class _QuillToolbarSelectAlignmentButtonState +class QuillToolbarSelectAlignmentButtonState extends State { Attribute? _value; @@ -149,7 +149,7 @@ class _QuillToolbarSelectAlignmentButtonState @override Widget build(BuildContext context) { - final _valueToText = { + final valueToText = { if (widget.showLeftAlignment!) Attribute.leftAlignment: Attribute.leftAlignment.value!, if (widget.showCenterAlignment!) @@ -160,13 +160,13 @@ class _QuillToolbarSelectAlignmentButtonState Attribute.justifyAlignment: Attribute.justifyAlignment.value!, }; - final _valueAttribute = [ + final valueAttribute = [ if (widget.showLeftAlignment!) Attribute.leftAlignment, if (widget.showCenterAlignment!) Attribute.centerAlignment, if (widget.showRightAlignment!) Attribute.rightAlignment, if (widget.showJustifyAlignment!) Attribute.justifyAlignment ]; - final _valueString = [ + final valueString = [ if (widget.showLeftAlignment!) Attribute.leftAlignment.value!, if (widget.showCenterAlignment!) Attribute.centerAlignment.value!, if (widget.showRightAlignment!) Attribute.rightAlignment.value!, @@ -191,12 +191,12 @@ class _QuillToolbarSelectAlignmentButtonState final childBuilder = options.childBuilder ?? baseButtonExtraOptions.childBuilder; - void _sharedOnPressed(int index) { - _valueAttribute[index] == Attribute.leftAlignment + void sharedOnPressed(int index) { + valueAttribute[index] == Attribute.leftAlignment ? controller.formatSelection( Attribute.clone(Attribute.align, null), ) - : controller.formatSelection(_valueAttribute[index]); + : controller.formatSelection(valueAttribute[index]); _afterButtonPressed?.call(); } @@ -215,7 +215,7 @@ class _QuillToolbarSelectAlignmentButtonState QuillToolbarSelectAlignmentButtonExtraOptions( context: context, controller: controller, - onPressed: () => _sharedOnPressed(index), + onPressed: () => sharedOnPressed(index), ), ); } @@ -229,11 +229,11 @@ class _QuillToolbarSelectAlignmentButtonState height: _iconSize * kIconButtonFactor, ), child: UtilityWidgets.maybeTooltip( - message: _valueString[index] == Attribute.leftAlignment.value + message: valueString[index] == Attribute.leftAlignment.value ? _tooltips.leftAlignment - : _valueString[index] == Attribute.centerAlignment.value + : valueString[index] == Attribute.centerAlignment.value ? _tooltips.centerAlignment - : _valueString[index] == Attribute.rightAlignment.value + : valueString[index] == Attribute.rightAlignment.value ? _tooltips.rightAlignment : _tooltips.justifyAlignment, child: RawMaterialButton( @@ -244,22 +244,21 @@ class _QuillToolbarSelectAlignmentButtonState shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(_iconTheme?.borderRadius ?? 2)), - fillColor: _valueToText[_value] == _valueString[index] + fillColor: valueToText[_value] == valueString[index] ? (_iconTheme?.iconSelectedFillColor ?? theme.primaryColor) : (_iconTheme?.iconUnselectedFillColor ?? theme.canvasColor), - onPressed: () => _sharedOnPressed(index), + onPressed: () => sharedOnPressed(index), child: Icon( - _valueString[index] == Attribute.leftAlignment.value + valueString[index] == Attribute.leftAlignment.value ? _iconsData.leftAlignment - : _valueString[index] == Attribute.centerAlignment.value + : valueString[index] == Attribute.centerAlignment.value ? _iconsData.centerAlignment - : _valueString[index] == - Attribute.rightAlignment.value + : valueString[index] == Attribute.rightAlignment.value ? _iconsData.rightAlignment : _iconsData.justifyAlignment, size: _iconSize, - color: _valueToText[_value] == _valueString[index] + color: valueToText[_value] == valueString[index] ? (_iconTheme?.iconSelectedColor ?? theme.primaryIconTheme.color) : (_iconTheme?.iconUnselectedColor ?? diff --git a/lib/src/widgets/toolbar/buttons/select_header_style.dart b/lib/src/widgets/toolbar/buttons/select_header_style.dart index 987f9f3e..15a05597 100644 --- a/lib/src/widgets/toolbar/buttons/select_header_style.dart +++ b/lib/src/widgets/toolbar/buttons/select_header_style.dart @@ -21,11 +21,11 @@ class QuillToolbarSelectHeaderStyleButtons extends StatefulWidget { final QuillToolbarSelectHeaderStyleButtonsOptions options; @override - _QuillToolbarSelectHeaderStyleButtonsState createState() => - _QuillToolbarSelectHeaderStyleButtonsState(); + QuillToolbarSelectHeaderStyleButtonsState createState() => + QuillToolbarSelectHeaderStyleButtonsState(); } -class _QuillToolbarSelectHeaderStyleButtonsState +class QuillToolbarSelectHeaderStyleButtonsState extends State { Attribute? _selectedAttribute; @@ -85,9 +85,9 @@ class _QuillToolbarSelectHeaderStyleButtonsState } void _sharedOnPressed(Attribute attribute) { - final _attribute = + final attribute0 = _selectedAttribute == attribute ? Attribute.header : attribute; - controller.formatSelection(_attribute); + controller.formatSelection(attribute0); afterButtonPressed?.call(); } diff --git a/lib/src/widgets/toolbar/buttons/toggle_check_list.dart b/lib/src/widgets/toolbar/buttons/toggle_check_list.dart index 189b9a30..b30a2243 100644 --- a/lib/src/widgets/toolbar/buttons/toggle_check_list.dart +++ b/lib/src/widgets/toolbar/buttons/toggle_check_list.dart @@ -23,11 +23,11 @@ class QuillToolbarToggleCheckListButton extends StatefulWidget { final QuillController controller; @override - _QuillToolbarToggleCheckListButtonState createState() => - _QuillToolbarToggleCheckListButtonState(); + QuillToolbarToggleCheckListButtonState createState() => + QuillToolbarToggleCheckListButtonState(); } -class _QuillToolbarToggleCheckListButtonState +class QuillToolbarToggleCheckListButtonState extends State { bool? _isToggled; diff --git a/lib/src/widgets/toolbar/buttons/toggle_style.dart b/lib/src/widgets/toolbar/buttons/toggle_style.dart index 38b8bc6b..04a27c03 100644 --- a/lib/src/widgets/toolbar/buttons/toggle_style.dart +++ b/lib/src/widgets/toolbar/buttons/toggle_style.dart @@ -36,11 +36,11 @@ class QuillToolbarToggleStyleButton extends StatefulWidget { final QuillController controller; @override - _QuillToolbarToggleStyleButtonState createState() => - _QuillToolbarToggleStyleButtonState(); + QuillToolbarToggleStyleButtonState createState() => + QuillToolbarToggleStyleButtonState(); } -class _QuillToolbarToggleStyleButtonState +class QuillToolbarToggleStyleButtonState extends State { bool? _isToggled; diff --git a/pubspec.yaml b/pubspec.yaml index 4eae9614..5be31f2b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill description: A rich text editor built for the modern Android, iOS, web and desktop platforms. It is the WYSIWYG editor and a Quill component for Flutter. -version: 8.1.10 +version: 8.1.11 homepage: https://1o24bbs.com/c/bulletjournal/108 repository: https://github.com/singerdmx/flutter-quill @@ -42,12 +42,10 @@ dependencies: flutter_keyboard_visibility: ^5.4.1 quiver: ^3.2.1 url_launcher: ^6.1.14 - pedantic: ^1.11.1 characters: ^1.3.0 diff_match_patch: ^0.4.1 i18n_extension: ^9.0.2 device_info_plus: ^9.1.0 - platform: ^3.1.0 pasteboard: ^0.2.0 equatable: ^2.0.5 flutter_animate: ^4.2.0+1 @@ -56,4 +54,7 @@ dependencies: sdk: flutter meta: ^1.9.1 -flutter: null \ No newline at end of file +flutter: + uses-material-design: true +dev_dependencies: + lints: ^3.0.0 \ No newline at end of file diff --git a/test/widgets/controller_test.dart b/test/widgets/controller_test.dart index e2405d4b..3decfc47 100644 --- a/test/widgets/controller_test.dart +++ b/test/widgets/controller_test.dart @@ -9,7 +9,7 @@ void main() { setUp(() { controller = QuillController.basic() ..compose(Delta()..insert(testDocumentContents), - const TextSelection.collapsed(offset: 0), ChangeSource.LOCAL); + const TextSelection.collapsed(offset: 0), ChangeSource.local); }); group('controller', () { @@ -31,7 +31,7 @@ void main() { controller ..formatText(0, 5, Attribute.h1) ..updateSelection(const TextSelection(baseOffset: 0, extentOffset: 4), - ChangeSource.LOCAL); + ChangeSource.local); expect(controller.getSelectionStyle().values, [Attribute.h1]); }); @@ -41,7 +41,7 @@ void main() { // With selection range controller ..updateSelection(const TextSelection(baseOffset: 0, extentOffset: 4), - ChangeSource.LOCAL) + ChangeSource.local) ..addListener(() { listenerCalled = true; }) @@ -58,12 +58,12 @@ void main() { // With collapsed selection controller ..updateSelection( - const TextSelection.collapsed(offset: 0), ChangeSource.LOCAL) + const TextSelection.collapsed(offset: 0), ChangeSource.local) ..indentSelection(true); expect(controller.getSelectionStyle().values, [Attribute.indentL1]); controller ..updateSelection( - const TextSelection.collapsed(offset: 0), ChangeSource.LOCAL) + const TextSelection.collapsed(offset: 0), ChangeSource.local) ..indentSelection(true); expect(controller.getSelectionStyle().values, [Attribute.indentL2]); controller.indentSelection(false); @@ -75,17 +75,17 @@ void main() { test('indentSelection with multiline document', () { controller ..compose(Delta()..insert('line1\nline2\nline3\n'), - const TextSelection.collapsed(offset: 0), ChangeSource.LOCAL) + const TextSelection.collapsed(offset: 0), ChangeSource.local) // Indent first line ..updateSelection( - const TextSelection.collapsed(offset: 0), ChangeSource.LOCAL) + const TextSelection.collapsed(offset: 0), ChangeSource.local) ..indentSelection(true); expect(controller.getSelectionStyle().values, [Attribute.indentL1]); // Indent first two lines controller ..updateSelection(const TextSelection(baseOffset: 0, extentOffset: 11), - ChangeSource.LOCAL) + ChangeSource.local) ..indentSelection(true); // Should have both L1 and L2 indent attributes in selection. @@ -101,7 +101,7 @@ void main() { TextSelection( baseOffset: 12, extentOffset: controller.document.toPlainText().length - 1), - ChangeSource.LOCAL); + ChangeSource.local); expect(controller.getAllSelectionStyles(), everyElement(const Style())); }); @@ -110,7 +110,7 @@ void main() { ..formatText(0, 2, Attribute.bold) ..replaceText(2, 2, BlockEmbed.image('/test'), null) ..updateSelection(const TextSelection(baseOffset: 0, extentOffset: 4), - ChangeSource.REMOTE); + ChangeSource.remote); final result = controller.getAllIndividualSelectionStylesAndEmbed(); expect(result.length, 2); expect(result[0].offset, 0); @@ -121,7 +121,7 @@ void main() { test('getPlainText', () { controller.updateSelection( const TextSelection(baseOffset: 0, extentOffset: 4), - ChangeSource.LOCAL); + ChangeSource.local); expect(controller.getPlainText(), testDocumentContents); }); @@ -135,7 +135,7 @@ void main() { test('undo', () { var listenerCalled = false; controller.updateSelection( - const TextSelection.collapsed(offset: 4), ChangeSource.LOCAL); + const TextSelection.collapsed(offset: 4), ChangeSource.local); expect( controller.document.toDelta(), @@ -153,7 +153,7 @@ void main() { test('redo', () { var listenerCalled = false; controller.updateSelection( - const TextSelection.collapsed(offset: 4), ChangeSource.LOCAL); + const TextSelection.collapsed(offset: 4), ChangeSource.local); expect(controller.document.toDelta(), Delta()..insert('data\n')); controller.undo(); @@ -222,7 +222,7 @@ void main() { var listenerCalled = false; controller ..updateSelection(const TextSelection(baseOffset: 0, extentOffset: 2), - ChangeSource.LOCAL) + ChangeSource.local) ..addListener(() { listenerCalled = true; }) @@ -238,7 +238,7 @@ void main() { var listenerCalled = false; controller ..updateSelection( - const TextSelection.collapsed(offset: 4), ChangeSource.LOCAL) + const TextSelection.collapsed(offset: 4), ChangeSource.local) ..addListener(() { listenerCalled = true; }); @@ -281,7 +281,7 @@ void main() { ..addListener(() { listenerCalled = true; }) - ..updateSelection(selection, ChangeSource.LOCAL); + ..updateSelection(selection, ChangeSource.local); expect(listenerCalled, isTrue); expect(controller.selection, selection); @@ -295,7 +295,7 @@ void main() { listenerCalled = true; }) ..compose(Delta()..insert('test '), - const TextSelection.collapsed(offset: 0), ChangeSource.LOCAL); + const TextSelection.collapsed(offset: 0), ChangeSource.local); expect(listenerCalled, isTrue); expect(controller.document.toDelta(),