From 718912bc29524da9f603f6d406ba2a319c8bab95 Mon Sep 17 00:00:00 2001 From: Xin Yao Date: Thu, 25 Mar 2021 00:07:30 -0700 Subject: [PATCH] Clear hints --- lib/models/documents/nodes/container.dart | 10 ++-- lib/models/documents/nodes/leaf.dart | 16 +++--- lib/models/documents/nodes/line.dart | 20 +++---- lib/models/documents/nodes/node.dart | 8 +-- lib/models/rules/delete.dart | 4 +- lib/models/rules/format.dart | 4 +- lib/models/rules/insert.dart | 12 ++-- lib/models/rules/rule.dart | 6 +- lib/utils/color.dart | 2 +- lib/utils/universal_ui/fake_ui.dart | 2 +- lib/utils/universal_ui/real_ui.dart | 2 +- lib/utils/universal_ui/universal_ui.dart | 2 +- lib/widgets/controller.dart | 18 +++--- lib/widgets/cursor.dart | 14 ++--- lib/widgets/default_styles.dart | 36 ++++++------ lib/widgets/delegate.dart | 4 +- lib/widgets/editor.dart | 60 ++++++++++--------- lib/widgets/proxy.dart | 4 +- lib/widgets/raw_editor.dart | 46 +++++++-------- lib/widgets/text_block.dart | 70 +++++++++++------------ lib/widgets/text_line.dart | 64 ++++++++++----------- pubspec.yaml | 2 +- 22 files changed, 202 insertions(+), 204 deletions(-) diff --git a/lib/models/documents/nodes/container.dart b/lib/models/documents/nodes/container.dart index 2e1c29fa..c7c10390 100644 --- a/lib/models/documents/nodes/container.dart +++ b/lib/models/documents/nodes/container.dart @@ -25,13 +25,13 @@ abstract class Container extends Node { /// abstract methods end - add(T node) { + void add(T node) { assert(node?.parent == null); node?.parent = this; _children.add(node as Node); } - addFirst(T node) { + void addFirst(T node) { assert(node?.parent == null); node?.parent = this; _children.addFirst(node as Node); @@ -80,7 +80,7 @@ abstract class Container extends Node { int get length => _children.fold(0, (cur, node) => cur + node.length); @override - insert(int index, Object data, Style? style) { + void insert(int index, Object data, Style? style) { assert(index == 0 || (index > 0 && index < length)); if (isNotEmpty) { @@ -97,14 +97,14 @@ abstract class Container extends Node { } @override - retain(int index, int? length, Style? attributes) { + void retain(int index, int? length, Style? attributes) { assert(isNotEmpty); ChildQuery child = queryChild(index, false); child.node!.retain(child.offset, length, attributes); } @override - delete(int index, int? length) { + void delete(int index, int? length) { assert(isNotEmpty); ChildQuery child = queryChild(index, false); child.node!.delete(child.offset, length); diff --git a/lib/models/documents/nodes/leaf.dart b/lib/models/documents/nodes/leaf.dart index 804c9a10..efb2ccde 100644 --- a/lib/models/documents/nodes/leaf.dart +++ b/lib/models/documents/nodes/leaf.dart @@ -50,7 +50,7 @@ abstract class Leaf extends Node { } @override - insert(int index, Object data, Style? style) { + void insert(int index, Object data, Style? style) { assert(index >= 0 && index <= length); Leaf node = Leaf(data); if (index < length) { @@ -62,12 +62,12 @@ abstract class Leaf extends Node { } @override - retain(int index, int? len, Style? style) { + void retain(int index, int? len, Style? style) { if (style == null) { return; } - int local = math.min(this.length - index, len!); + int local = math.min(length - index, len!); int remain = len - local; Leaf node = _isolate(index, local); @@ -79,10 +79,10 @@ abstract class Leaf extends Node { } @override - delete(int index, int? len) { - assert(index < this.length); + void delete(int index, int? len) { + assert(index < length); - int local = math.min(this.length - index, len!); + int local = math.min(length - index, len!); Leaf target = _isolate(index, local); Leaf? prev = target.previous as Leaf?; Leaf? next = target.next as Leaf?; @@ -100,7 +100,7 @@ abstract class Leaf extends Node { } @override - adjust() { + void adjust() { if (this is Embed) { return; } @@ -147,7 +147,7 @@ abstract class Leaf extends Node { return split; } - format(Style? style) { + void format(Style? style) { if (style != null && style.isNotEmpty) { applyStyle(style); } diff --git a/lib/models/documents/nodes/line.dart b/lib/models/documents/nodes/line.dart index 4e3b1ac0..574549ea 100644 --- a/lib/models/documents/nodes/line.dart +++ b/lib/models/documents/nodes/line.dart @@ -66,7 +66,7 @@ class Line extends Container { } @override - insert(int index, Object data, Style? style) { + void insert(int index, Object data, Style? style) { if (data is Embeddable) { _insert(index, data, style); return; @@ -101,11 +101,11 @@ class Line extends Container { } @override - retain(int index, int? len, Style? style) { + void retain(int index, int? len, Style? style) { if (style == null) { return; } - int thisLen = this.length; + int thisLen = length; int local = math.min(thisLen - index, len!); @@ -126,9 +126,9 @@ class Line extends Container { } @override - delete(int index, int? len) { - int local = math.min(this.length - index, len!); - bool deleted = index + local == this.length; + void delete(int index, int? len) { + int local = math.min(length - index, len!); + bool deleted = index + local == length; if (deleted) { clearStyle(); if (local > 1) { @@ -187,14 +187,14 @@ class Line extends Container { } } - _wrap(Block block) { + void _wrap(Block block) { assert(parent != null && parent is! Block); insertAfter(block); unlink(); block.add(this); } - _unwrap() { + void _unwrap() { if (parent is! Block) { throw ArgumentError('Invalid parent'); } @@ -246,7 +246,7 @@ class Line extends Container { return line; } - _insert(int index, Object data, Style? style) { + void _insert(int index, Object data, Style? style) { assert(index == 0 || (index > 0 && index < length)); if (data is String) { @@ -273,7 +273,7 @@ class Line extends Container { } Style collectStyle(int offset, int len) { - int local = math.min(this.length - offset, len); + int local = math.min(length - offset, len); Style res = Style(); var excluded = {}; diff --git a/lib/models/documents/nodes/node.dart b/lib/models/documents/nodes/node.dart index 984ed0a1..abc093c3 100644 --- a/lib/models/documents/nodes/node.dart +++ b/lib/models/documents/nodes/node.dart @@ -84,7 +84,7 @@ abstract class Node extends LinkedListEntry { super.unlink(); } - adjust() { + void adjust() { // do nothing } @@ -96,11 +96,11 @@ abstract class Node extends LinkedListEntry { Delta toDelta(); - insert(int index, Object data, Style? style); + void insert(int index, Object data, Style? style); - retain(int index, int? len, Style? style); + void retain(int index, int? len, Style? style); - delete(int index, int? len); + void delete(int index, int? len); /// abstract methods end diff --git a/lib/models/rules/delete.dart b/lib/models/rules/delete.dart index 8f590231..15aa3862 100644 --- a/lib/models/rules/delete.dart +++ b/lib/models/rules/delete.dart @@ -9,7 +9,7 @@ abstract class DeleteRule extends Rule { RuleType get type => RuleType.DELETE; @override - validateArgs(int? len, Object? data, Attribute? attribute) { + void validateArgs(int? len, Object? data, Attribute? attribute) { assert(len != null); assert(data == null); assert(attribute == null); @@ -54,7 +54,7 @@ class PreserveLineStyleOnMergeRule extends DeleteRule { String text = op.data is String ? (op.data as String?)! : ''; int lineBreak = text.indexOf('\n'); if (lineBreak == -1) { - delta..retain(op.length!); + delta.retain(op.length!); continue; } diff --git a/lib/models/rules/format.dart b/lib/models/rules/format.dart index f5875833..755f4137 100644 --- a/lib/models/rules/format.dart +++ b/lib/models/rules/format.dart @@ -9,7 +9,7 @@ abstract class FormatRule extends Rule { RuleType get type => RuleType.FORMAT; @override - validateArgs(int? len, Object? data, Attribute? attribute) { + void validateArgs(int? len, Object? data, Attribute? attribute) { assert(len != null); assert(data == null); assert(attribute != null); @@ -55,7 +55,7 @@ class ResolveLineFormatRule extends FormatRule { String text = op.data is String ? (op.data as String?)! : ''; int lineBreak = text.indexOf('\n'); if (lineBreak < 0) { - delta..retain(op.length!); + delta.retain(op.length!); continue; } delta..retain(lineBreak)..retain(1, attribute.toJson()); diff --git a/lib/models/rules/insert.dart b/lib/models/rules/insert.dart index 61829972..62585ec3 100644 --- a/lib/models/rules/insert.dart +++ b/lib/models/rules/insert.dart @@ -11,7 +11,7 @@ abstract class InsertRule extends Rule { RuleType get type => RuleType.INSERT; @override - validateArgs(int? len, Object? data, Attribute? attribute) { + void validateArgs(int? len, Object? data, Attribute? attribute) { assert(len == null); assert(data != null); assert(attribute == null); @@ -45,7 +45,7 @@ class PreserveLineStyleOnSplitRule extends InsertRule { Delta delta = Delta()..retain(index); if (text.contains('\n')) { assert(after.isPlain); - delta..insert('\n'); + delta.insert('\n'); return delta; } Tuple2 nextNewLine = _getNextNewLine(itr); @@ -222,7 +222,7 @@ class InsertEmbedsRule extends InsertRule { } else { while (itr.hasNext) { Operation op = itr.next(); - if ((op.data is String ? op.data as String? : '')!.indexOf('\n') >= 0) { + if ((op.data is String ? op.data as String? : '')!.contains('\n')) { lineStyle = op.attributes; break; } @@ -230,11 +230,11 @@ class InsertEmbedsRule extends InsertRule { } if (!isNewlineBefore) { - delta..insert('\n', lineStyle); + delta.insert('\n', lineStyle); } - delta..insert(data); + delta.insert(data); if (!isNewlineAfter) { - delta..insert('\n'); + delta.insert('\n'); } return delta; } diff --git a/lib/models/rules/rule.dart b/lib/models/rules/rule.dart index a549c22f..da83797b 100644 --- a/lib/models/rules/rule.dart +++ b/lib/models/rules/rule.dart @@ -18,7 +18,7 @@ abstract class Rule { len: len, data: data, attribute: attribute); } - validateArgs(int? len, Object? data, Attribute? attribute); + void validateArgs(int? len, Object? data, Attribute? attribute); Delta? applyRule(Delta document, int index, {int? len, Object? data, Attribute? attribute}); @@ -61,11 +61,11 @@ class Rules { final result = rule.apply(delta, index, len: len, data: data, attribute: attribute); if (result != null) { - print("Rule $rule applied"); + print('Rule $rule applied'); return result..trim(); } } catch (e) { - throw e; + rethrow; } } throw ('Apply rules failed'); diff --git a/lib/utils/color.dart b/lib/utils/color.dart index c7f467fa..4bc1c55a 100644 --- a/lib/utils/color.dart +++ b/lib/utils/color.dart @@ -115,7 +115,7 @@ Color stringToColor(String? s) { } if (!s.startsWith('#')) { - throw ("Color code not supported"); + throw ('Color code not supported'); } String hex = s.replaceFirst('#', ''); diff --git a/lib/utils/universal_ui/fake_ui.dart b/lib/utils/universal_ui/fake_ui.dart index 3c59b5d2..1711ad5f 100644 --- a/lib/utils/universal_ui/fake_ui.dart +++ b/lib/utils/universal_ui/fake_ui.dart @@ -1,3 +1,3 @@ class PlatformViewRegistry { - static registerViewFactory(String viewId, dynamic cb) {} + static void registerViewFactory(String viewId, dynamic cb) {} } diff --git a/lib/utils/universal_ui/real_ui.dart b/lib/utils/universal_ui/real_ui.dart index f699c9c0..b701caf4 100644 --- a/lib/utils/universal_ui/real_ui.dart +++ b/lib/utils/universal_ui/real_ui.dart @@ -1,7 +1,7 @@ import 'dart:ui' as ui; class PlatformViewRegistry { - static registerViewFactory(String viewId, dynamic cb) { + static void registerViewFactory(String viewId, dynamic cb) { ui.platformViewRegistry.registerViewFactory(viewId, cb); } } diff --git a/lib/utils/universal_ui/universal_ui.dart b/lib/utils/universal_ui/universal_ui.dart index 307520c5..5fe7c428 100644 --- a/lib/utils/universal_ui/universal_ui.dart +++ b/lib/utils/universal_ui/universal_ui.dart @@ -4,7 +4,7 @@ import 'package:flutter/foundation.dart'; import 'fake_ui.dart' if (dart.library.html) 'real_ui.dart' as ui_instance; class PlatformViewRegistryFix { - registerViewFactory(dynamic x, dynamic y) { + void registerViewFactory(dynamic x, dynamic y) { if (kIsWeb) { ui_instance.PlatformViewRegistry.registerViewFactory( x, diff --git a/lib/widgets/controller.dart b/lib/widgets/controller.dart index 2ea56e32..665211a9 100644 --- a/lib/widgets/controller.dart +++ b/lib/widgets/controller.dart @@ -54,7 +54,7 @@ class QuillController extends ChangeNotifier { // updateSelection( // TextSelection.collapsed(offset: document.length), ChangeSource.LOCAL); updateSelection( - TextSelection.collapsed(offset: this.selection.baseOffset + len!), + TextSelection.collapsed(offset: selection.baseOffset + len!), ChangeSource.LOCAL); } else { // no need to move cursor @@ -73,7 +73,7 @@ class QuillController extends ChangeNotifier { get hasRedo => document.hasRedo; - replaceText(int index, int len, Object? data, TextSelection? textSelection) { + void replaceText(int index, int len, Object? data, TextSelection? textSelection) { assert(data is String || data is Embeddable); Delta? delta; @@ -82,7 +82,7 @@ class QuillController extends ChangeNotifier { delta = document.replace(index, len, data); } catch (e) { print('document.replace failed: $e'); - throw e; + rethrow; } bool shouldRetainDelta = toggledStyle.isNotEmpty && delta.isNotEmpty && @@ -127,14 +127,14 @@ class QuillController extends ChangeNotifier { ); } catch (e) { print('getPositionDelta or getPositionDelta error: $e'); - throw e; + rethrow; } } } notifyListeners(); } - formatText(int index, int len, Attribute? attribute) { + void formatText(int index, int len, Attribute? attribute) { if (len == 0 && attribute!.isInline && attribute.key != Attribute.link.key) { @@ -151,16 +151,16 @@ class QuillController extends ChangeNotifier { notifyListeners(); } - formatSelection(Attribute? attribute) { + void formatSelection(Attribute? attribute) { formatText(selection.start, selection.end - selection.start, attribute); } - updateSelection(TextSelection textSelection, ChangeSource source) { + void updateSelection(TextSelection textSelection, ChangeSource source) { _updateSelection(textSelection, source); notifyListeners(); } - compose(Delta delta, TextSelection textSelection, ChangeSource source) { + void compose(Delta delta, TextSelection textSelection, ChangeSource source) { if (delta.isNotEmpty) { document.compose(delta, source); } @@ -182,7 +182,7 @@ class QuillController extends ChangeNotifier { super.dispose(); } - _updateSelection(TextSelection textSelection, ChangeSource source) { + void _updateSelection(TextSelection textSelection, ChangeSource source) { selection = textSelection; int end = document.length - 1; selection = selection.copyWith( diff --git a/lib/widgets/cursor.dart b/lib/widgets/cursor.dart index d6305569..8fa45437 100644 --- a/lib/widgets/cursor.dart +++ b/lib/widgets/cursor.dart @@ -89,7 +89,7 @@ class CursorCont extends ChangeNotifier { } @override - dispose() { + void dispose() { _blinkOpacityCont.removeListener(_onColorTick); stopCursorTimer(); _blinkOpacityCont.dispose(); @@ -97,7 +97,7 @@ class CursorCont extends ChangeNotifier { super.dispose(); } - _cursorTick(Timer timer) { + void _cursorTick(Timer timer) { _targetCursorVisibility = !_targetCursorVisibility; double targetOpacity = _targetCursorVisibility ? 1.0 : 0.0; if (style.opacityAnimates) { @@ -107,7 +107,7 @@ class CursorCont extends ChangeNotifier { } } - _cursorWaitForStart(Timer timer) { + void _cursorWaitForStart(Timer timer) { _cursorTimer?.cancel(); _cursorTimer = Timer.periodic(Duration(milliseconds: 500), _cursorTick); } @@ -124,7 +124,7 @@ class CursorCont extends ChangeNotifier { } } - stopCursorTimer({bool resetCharTicks = true}) { + void stopCursorTimer({bool resetCharTicks = true}) { _cursorTimer?.cancel(); _cursorTimer = null; _targetCursorVisibility = false; @@ -136,7 +136,7 @@ class CursorCont extends ChangeNotifier { } } - startOrStopCursorTimerIfNeeded(bool hasFocus, TextSelection selection) { + void startOrStopCursorTimerIfNeeded(bool hasFocus, TextSelection selection) { if (show.value && _cursorTimer == null && hasFocus && @@ -147,7 +147,7 @@ class CursorCont extends ChangeNotifier { } } - _onColorTick() { + void _onColorTick() { color.value = _style.color.withOpacity(_blinkOpacityCont.value); _blink.value = show.value && _blinkOpacityCont.value > 0; } @@ -163,7 +163,7 @@ class CursorPainter { CursorPainter(this.editable, this.style, this.prototype, this.color, this.devicePixelRatio); - paint(Canvas canvas, Offset offset, TextPosition position) { + void paint(Canvas canvas, Offset offset, TextPosition position) { assert(prototype != null); Offset caretOffset = diff --git a/lib/widgets/default_styles.dart b/lib/widgets/default_styles.dart index 7beb9f5c..bbe8db10 100644 --- a/lib/widgets/default_styles.dart +++ b/lib/widgets/default_styles.dart @@ -188,23 +188,23 @@ class DefaultStyles { DefaultStyles merge(DefaultStyles other) { return DefaultStyles( - h1: other.h1 ?? this.h1, - h2: other.h2 ?? this.h2, - h3: other.h3 ?? this.h3, - paragraph: other.paragraph ?? this.paragraph, - bold: other.bold ?? this.bold, - italic: other.italic ?? this.italic, - underline: other.underline ?? this.underline, - strikeThrough: other.strikeThrough ?? this.strikeThrough, - link: other.link ?? this.link, - placeHolder: other.placeHolder ?? this.placeHolder, - lists: other.lists ?? this.lists, - quote: other.quote ?? this.quote, - code: other.code ?? this.code, - indent: other.indent ?? this.indent, - align: other.align ?? this.align, - sizeSmall: other.sizeSmall ?? this.sizeSmall, - sizeLarge: other.sizeLarge ?? this.sizeLarge, - sizeHuge: other.sizeHuge ?? this.sizeHuge); + h1: other.h1 ?? h1, + h2: other.h2 ?? h2, + h3: other.h3 ?? h3, + paragraph: other.paragraph ?? paragraph, + bold: other.bold ?? bold, + italic: other.italic ?? italic, + underline: other.underline ?? underline, + strikeThrough: other.strikeThrough ?? strikeThrough, + link: other.link ?? link, + placeHolder: other.placeHolder ?? placeHolder, + lists: other.lists ?? lists, + quote: other.quote ?? quote, + code: other.code ?? code, + indent: other.indent ?? indent, + align: other.align ?? align, + sizeSmall: other.sizeSmall ?? sizeSmall, + sizeLarge: other.sizeLarge ?? sizeLarge, + sizeHuge: other.sizeHuge ?? sizeHuge); } } diff --git a/lib/widgets/delegate.dart b/lib/widgets/delegate.dart index 3fa51fab..13cf999d 100644 --- a/lib/widgets/delegate.dart +++ b/lib/widgets/delegate.dart @@ -28,7 +28,7 @@ class EditorTextSelectionGestureDetectorBuilder { } RenderEditor? getRenderEditor() { - return this.getEditor()!.getRenderEditor(); + return getEditor()!.getRenderEditor(); } onTapDown(TapDownDetails details) { @@ -124,7 +124,7 @@ class EditorTextSelectionGestureDetectorBuilder { ); } - onDragSelectionEnd(DragEndDetails details) {} + void onDragSelectionEnd(DragEndDetails details) {} Widget build(HitTestBehavior behavior, Widget child) { return EditorTextSelectionGestureDetector( diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 53eef90b..c939d5fe 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -11,7 +11,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_quill/models/documents/attribute.dart'; import 'package:flutter_quill/models/documents/document.dart'; import 'package:flutter_quill/models/documents/nodes/container.dart' - as containerNode; + as container_node; import 'package:flutter_quill/models/documents/nodes/embed.dart'; import 'package:flutter_quill/models/documents/nodes/leaf.dart' as leaf; import 'package:flutter_quill/models/documents/nodes/line.dart'; @@ -94,8 +94,8 @@ abstract class RenderAbstractEditor { } String _standardizeImageUrl(String url) { - if (url.contains("base64")) { - return url.split(",")[1]; + if (url.contains('base64')) { + return url.split(',')[1]; } return url; } @@ -211,7 +211,7 @@ class QuillEditor extends StatefulWidget { class _QuillEditorState extends State implements EditorTextSelectionGestureDetectorBuilderDelegate { - GlobalKey _editorKey = GlobalKey(); + final GlobalKey _editorKey = GlobalKey(); late EditorTextSelectionGestureDetectorBuilder _selectionGestureDetectorBuilder; @@ -382,13 +382,13 @@ class _QuillEditorSelectionGestureDetectorBuilder } TextPosition pos = getRenderEditor()!.getPositionForOffset(details.globalPosition); - containerNode.ChildQuery result = + container_node.ChildQuery result = getEditor()!.widget.controller.document.queryChild(pos.offset); if (result.node == null) { return false; } Line line = result.node as Line; - containerNode.ChildQuery segmentResult = + container_node.ChildQuery segmentResult = line.queryChild(result.offset, false); if (segmentResult.node == null) { if (line.length == 1) { @@ -403,9 +403,7 @@ class _QuillEditorSelectionGestureDetectorBuilder leaf.Leaf segment = segmentResult.node as leaf.Leaf; if (segment.style.containsKey(Attribute.link.key)) { var launchUrl = getEditor()!.widget.onLaunchUrl; - if (launchUrl == null) { - launchUrl = _launchUrl; - } + launchUrl ??= _launchUrl; String? link = segment.style.attributes[Attribute.link.key]!.value; if (getEditor()!.widget.readOnly && link != null) { link = link.trim(); @@ -444,7 +442,7 @@ class _QuillEditorSelectionGestureDetectorBuilder } bool _flipListCheckbox( - TextPosition pos, Line line, containerNode.ChildQuery segmentResult) { + TextPosition pos, Line line, container_node.ChildQuery segmentResult) { if (getEditor()!.widget.readOnly || !line.style.containsKey(Attribute.list.key) || segmentResult.offset != 0) { @@ -473,7 +471,7 @@ class _QuillEditorSelectionGestureDetectorBuilder } @override - onSingleTapUp(TapUpDetails details) { + void onSingleTapUp(TapUpDetails details) { getEditor()!.hideToolbar(); bool positionSelected = _onTapping(details); @@ -569,7 +567,7 @@ class RenderEditor extends RenderEditableContainerBox padding, ); - setDocument(Document doc) { + void setDocument(Document doc) { if (document == doc) { return; } @@ -577,7 +575,7 @@ class RenderEditor extends RenderEditableContainerBox markNeedsLayout(); } - setHasFocus(bool h) { + void setHasFocus(bool h) { if (_hasFocus == h) { return; } @@ -585,7 +583,7 @@ class RenderEditor extends RenderEditableContainerBox markNeedsSemanticsUpdate(); } - setSelection(TextSelection t) { + void setSelection(TextSelection t) { if (selection == t) { return; } @@ -593,7 +591,7 @@ class RenderEditor extends RenderEditableContainerBox markNeedsPaint(); } - setStartHandleLayerLink(LayerLink value) { + void setStartHandleLayerLink(LayerLink value) { if (_startHandleLayerLink == value) { return; } @@ -601,7 +599,7 @@ class RenderEditor extends RenderEditableContainerBox markNeedsPaint(); } - setEndHandleLayerLink(LayerLink value) { + void setEndHandleLayerLink(LayerLink value) { if (_endHandleLayerLink == value) { return; } @@ -671,12 +669,12 @@ class RenderEditor extends RenderEditableContainerBox Offset? _lastTapDownPosition; @override - handleTapDown(TapDownDetails details) { + void handleTapDown(TapDownDetails details) { _lastTapDownPosition = details.globalPosition; } @override - selectWordsInRange( + void selectWordsInRange( Offset from, Offset? to, SelectionChangedCause cause, @@ -696,7 +694,7 @@ class RenderEditor extends RenderEditableContainerBox ); } - _handleSelectionChange( + void _handleSelectionChange( TextSelection nextSelection, SelectionChangedCause cause, ) { @@ -712,7 +710,7 @@ class RenderEditor extends RenderEditableContainerBox } @override - selectWordEdge(SelectionChangedCause cause) { + void selectWordEdge(SelectionChangedCause cause) { assert(_lastTapDownPosition != null); TextPosition position = getPositionForOffset(_lastTapDownPosition!); RenderEditableBox child = childAtPosition(position); @@ -742,7 +740,7 @@ class RenderEditor extends RenderEditableContainerBox } @override - selectPositionAt( + void selectPositionAt( Offset from, Offset? to, SelectionChangedCause cause, @@ -766,12 +764,12 @@ class RenderEditor extends RenderEditableContainerBox } @override - selectWord(SelectionChangedCause cause) { + void selectWord(SelectionChangedCause cause) { selectWordsInRange(_lastTapDownPosition!, null, cause); } @override - selectPosition(SelectionChangedCause cause) { + void selectPosition(SelectionChangedCause cause) { selectPositionAt(_lastTapDownPosition!, null, cause); } @@ -821,7 +819,7 @@ class RenderEditor extends RenderEditableContainerBox return defaultHitTestChildren(result, position: position); } - _paintHandleLayers( + void _paintHandleLayers( PaintingContext context, List endpoints) { var startPoint = endpoints[0].point; startPoint = Offset( @@ -904,7 +902,7 @@ class RenderEditableContainerBox extends RenderBox EditableContainerParentData>, RenderBoxContainerDefaultsMixin { - containerNode.Container _container; + container_node.Container _container; TextDirection textDirection; EdgeInsetsGeometry _padding; EdgeInsets? _resolvedPadding; @@ -915,11 +913,11 @@ class RenderEditableContainerBox extends RenderBox addAll(children); } - containerNode.Container getContainer() { + container_node.Container getContainer() { return _container; } - setContainer(containerNode.Container c) { + void setContainer(container_node.Container c) { if (_container == c) { return; } @@ -929,7 +927,7 @@ class RenderEditableContainerBox extends RenderBox EdgeInsetsGeometry getPadding() => _padding; - setPadding(EdgeInsetsGeometry value) { + void setPadding(EdgeInsetsGeometry value) { assert(value.isNonNegative); if (_padding == value) { return; @@ -940,7 +938,7 @@ class RenderEditableContainerBox extends RenderBox EdgeInsets? get resolvedPadding => _resolvedPadding; - _resolvePadding() { + void _resolvePadding() { if (_resolvedPadding != null) { return; } @@ -968,7 +966,7 @@ class RenderEditableContainerBox extends RenderBox return targetChild; } - _markNeedsPaddingResolution() { + void _markNeedsPaddingResolution() { _resolvedPadding = null; markNeedsLayout(); } @@ -997,7 +995,7 @@ class RenderEditableContainerBox extends RenderBox } @override - setupParentData(RenderBox child) { + void setupParentData(RenderBox child) { if (child.parentData is EditableContainerParentData) { return; } diff --git a/lib/widgets/proxy.dart b/lib/widgets/proxy.dart index 9f2e0bb3..f3e38c4e 100644 --- a/lib/widgets/proxy.dart +++ b/lib/widgets/proxy.dart @@ -66,7 +66,7 @@ class RenderBaselineProxy extends RenderProxyBox { // SEE What happens + _padding?.top; @override - performLayout() { + void performLayout() { super.performLayout(); _prototypePainter.layout(); } @@ -289,7 +289,7 @@ class RenderParagraphProxy extends RenderProxyBox child!.getBoxesForSelection(selection); @override - performLayout() { + void performLayout() { super.performLayout(); _prototypePainter.layout( minWidth: constraints.minWidth, maxWidth: constraints.maxWidth); diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index 1b9f4ad0..04b4aaf8 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -100,7 +100,7 @@ class RawEditorState extends EditorState WidgetsBindingObserver, TickerProviderStateMixin implements TextSelectionDelegate, TextInputClient { - GlobalKey _editorKey = GlobalKey(); + final GlobalKey _editorKey = GlobalKey(); final List _sentRemoteValues = []; TextInputConnection? _textInputConnection; TextEditingValue? _lastKnownRemoteTextEditingValue; @@ -144,7 +144,7 @@ class RawEditorState extends EditorState return result; } - handleCursorMovement( + void handleCursorMovement( LogicalKeyboardKey key, bool wordModifier, bool lineModifier, @@ -370,7 +370,7 @@ class RawEditorState extends EditorState bool get hasConnection => _textInputConnection != null && _textInputConnection!.attached; - openConnectionIfNeeded() { + void openConnectionIfNeeded() { if (!shouldCreateInputConnection) { return; } @@ -396,7 +396,7 @@ class RawEditorState extends EditorState _textInputConnection!.show(); } - closeConnectionIfNeeded() { + void closeConnectionIfNeeded() { if (!hasConnection) { return; } @@ -406,7 +406,7 @@ class RawEditorState extends EditorState _sentRemoteValues.clear(); } - updateRemoteValueIfNeeded() { + void updateRemoteValueIfNeeded() { if (!hasConnection) { return; } @@ -526,7 +526,6 @@ class RawEditorState extends EditorState child: Semantics( child: _Editor( key: _editorKey, - children: _buildChildren(_doc, context), document: _doc, selection: widget.controller.selection, hasFocus: _hasFocus, @@ -535,6 +534,7 @@ class RawEditorState extends EditorState endHandleLayerLink: _endHandleLayerLink, onSelectionChanged: _handleSelectionChanged, padding: widget.padding, + children: _buildChildren(_doc, context), ), ), ); @@ -571,7 +571,7 @@ class RawEditorState extends EditorState ); } - _handleSelectionChanged( + void _handleSelectionChanged( TextSelection selection, SelectionChangedCause cause) { widget.controller.updateSelection(selection, ChangeSource.LOCAL); @@ -582,7 +582,7 @@ class RawEditorState extends EditorState } } - _buildChildren(Document doc, BuildContext context) { + List _buildChildren(Document doc, BuildContext context) { final result = []; Map indentLevelCounts = {}; for (Node node in doc.root.children) { @@ -717,7 +717,7 @@ class RawEditorState extends EditorState } @override - didChangeDependencies() { + void didChangeDependencies() { super.didChangeDependencies(); DefaultStyles? parentStyles = QuillStyles.getStyles(context, true); DefaultStyles defaultStyles = DefaultStyles.getInstance(context); @@ -782,7 +782,7 @@ class RawEditorState extends EditorState !widget.controller.selection.isCollapsed; } - handleDelete(bool forward) { + void handleDelete(bool forward) { TextSelection selection = widget.controller.selection; String plainText = textEditingValue.text; int cursorPosition = selection.start; @@ -817,14 +817,14 @@ class RawEditorState extends EditorState String plainText = textEditingValue.text; if (shortcut == InputShortcut.COPY) { if (!selection.isCollapsed) { - Clipboard.setData(ClipboardData(text: selection.textInside(plainText))); + await Clipboard.setData(ClipboardData(text: selection.textInside(plainText))); } return; } if (shortcut == InputShortcut.CUT && !widget.readOnly) { if (!selection.isCollapsed) { final data = selection.textInside(plainText); - Clipboard.setData(ClipboardData(text: data)); + await Clipboard.setData(ClipboardData(text: data)); widget.controller.replaceText( selection.start, @@ -881,11 +881,11 @@ class RawEditorState extends EditorState super.dispose(); } - _updateSelectionOverlayForScroll() { + void _updateSelectionOverlayForScroll() { _selectionOverlay?.markNeedsBuild(); } - _didChangeTextEditingValue() { + void _didChangeTextEditingValue() { if (kIsWeb) { _onChangeTextEditingValue(); requestKeyboard(); @@ -899,7 +899,7 @@ class RawEditorState extends EditorState } } - _onChangeTextEditingValue() { + void _onChangeTextEditingValue() { _showCaretOnScreen(); updateRemoteValueIfNeeded(); _cursorCont.startOrStopCursorTimerIfNeeded( @@ -918,7 +918,7 @@ class RawEditorState extends EditorState }); } - _updateOrDisposeSelectionOverlayIfNeeded() { + void _updateOrDisposeSelectionOverlayIfNeeded() { if (_selectionOverlay != null) { if (_hasFocus) { _selectionOverlay!.update(textEditingValue); @@ -950,7 +950,7 @@ class RawEditorState extends EditorState } } - _handleFocusChanged() { + void _handleFocusChanged() { openOrCloseConnection(); _cursorCont.startOrStopCursorTimerIfNeeded( _hasFocus, widget.controller.selection); @@ -964,7 +964,7 @@ class RawEditorState extends EditorState updateKeepAlive(); } - _onChangedClipboardStatus() { + void _onChangedClipboardStatus() { if (!mounted) return; setState(() { // Inform the widget that the value of clipboardStatus has changed. @@ -974,7 +974,7 @@ class RawEditorState extends EditorState bool _showCaretOnScreenScheduled = false; - _showCaretOnScreen() { + void _showCaretOnScreen() { if (!widget.showCursor || _showCaretOnScreenScheduled) { return; } @@ -1039,7 +1039,7 @@ class RawEditorState extends EditorState bool get selectAllEnabled => widget.toolbarOptions.selectAll; @override - requestKeyboard() { + void requestKeyboard() { if (_hasFocus) { openConnectionIfNeeded(); } else { @@ -1048,7 +1048,7 @@ class RawEditorState extends EditorState } @override - setTextEditingValue(TextEditingValue value) { + void setTextEditingValue(TextEditingValue value) { if (value.text == textEditingValue.text) { widget.controller.updateSelection(value.selection, ChangeSource.LOCAL); } else { @@ -1116,7 +1116,7 @@ class RawEditorState extends EditorState @override bool get wantKeepAlive => widget.focusNode.hasFocus; - openOrCloseConnection() { + void openOrCloseConnection() { if (widget.focusNode.hasFocus && widget.focusNode.consumeKeyboardToken()) { openConnectionIfNeeded(); } else if (!widget.focusNode.hasFocus) { @@ -1164,7 +1164,7 @@ class _Editor extends MultiChildRenderObjectWidget { } @override - updateRenderObject( + void updateRenderObject( BuildContext context, covariant RenderEditor renderObject) { renderObject.document = document; renderObject.setContainer(document.root); diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index ee71e6e5..4d2a5cc3 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -32,19 +32,19 @@ const List arabianRomanNumbers = [ ]; const List romanNumbers = [ - "M", - "CM", - "D", - "CD", - "C", - "XC", - "L", - "XL", - "X", - "IX", - "V", - "IV", - "I" + 'M', + 'CM', + 'D', + 'CD', + 'C', + 'XC', + 'L', + 'XL', + 'X', + 'IX', + 'V', + 'IV', + 'I' ]; class EditableTextBlock extends StatelessWidget { @@ -86,7 +86,7 @@ class EditableTextBlock extends StatelessWidget { verticalSpacing as Tuple2, _getDecorationForBlock(block, defaultStyles) ?? BoxDecoration(), contentPadding, - _buildChildren(context, this.indentLevelCounts)); + _buildChildren(context, indentLevelCounts)); } BoxDecoration? _getDecorationForBlock( @@ -281,7 +281,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox } @override - setPadding(EdgeInsetsGeometry value) { + void setPadding(EdgeInsetsGeometry value) { super.setPadding(value.add(_contentPadding)); _savedPadding = value; } @@ -478,12 +478,12 @@ class RenderEditableTextBlock extends RenderEditableContainerBox } @override - paint(PaintingContext context, Offset offset) { + void paint(PaintingContext context, Offset offset) { _paintDecoration(context, offset); defaultPaint(context, offset); } - _paintDecoration(PaintingContext context, Offset offset) { + void _paintDecoration(PaintingContext context, Offset offset) { _painter ??= _decoration.createBoxPainter(markNeedsPaint); EdgeInsets decorationPadding = resolvedPadding! - _contentPadding; @@ -571,31 +571,31 @@ class _NumberPoint extends StatelessWidget { @override Widget build(BuildContext context) { - String s = this.index.toString(); + String s = index.toString(); int? level = 0; - if (!this.attrs.containsKey(Attribute.indent.key) && - !this.indentLevelCounts.containsKey(1)) { - this.indentLevelCounts.clear(); + if (!attrs.containsKey(Attribute.indent.key) && + !indentLevelCounts.containsKey(1)) { + indentLevelCounts.clear(); return Container( alignment: AlignmentDirectional.topEnd, - child: Text(withDot ? '$s.' : '$s', style: style), width: width, padding: EdgeInsetsDirectional.only(end: padding), + child: Text(withDot ? '$s.' : '$s', style: style), ); } - if (this.attrs.containsKey(Attribute.indent.key)) { - level = this.attrs[Attribute.indent.key]!.value; + if (attrs.containsKey(Attribute.indent.key)) { + level = attrs[Attribute.indent.key]!.value; } else { // first level but is back from previous indent level // supposed to be "2." - this.indentLevelCounts[0] = 1; + indentLevelCounts[0] = 1; } - if (this.indentLevelCounts.containsKey(level! + 1)) { + if (indentLevelCounts.containsKey(level! + 1)) { // last visited level is done, going up - this.indentLevelCounts.remove(level + 1); + indentLevelCounts.remove(level + 1); } - int count = (this.indentLevelCounts[level] ?? 0) + 1; - this.indentLevelCounts[level] = count; + int count = (indentLevelCounts[level] ?? 0) + 1; + indentLevelCounts[level] = count; s = count.toString(); if (level % 3 == 1) { @@ -609,9 +609,9 @@ class _NumberPoint extends StatelessWidget { return Container( alignment: AlignmentDirectional.topEnd, - child: Text(withDot ? '$s.' : '$s', style: style), width: width, padding: EdgeInsetsDirectional.only(end: padding), + child: Text(withDot ? '$s.' : '$s', style: style), ); } @@ -630,9 +630,9 @@ class _NumberPoint extends StatelessWidget { var num = input; if (num < 0) { - return ""; + return ''; } else if (num == 0) { - return "nulla"; + return 'nulla'; } final builder = StringBuffer(); @@ -665,9 +665,9 @@ class _BulletPoint extends StatelessWidget { Widget build(BuildContext context) { return Container( alignment: AlignmentDirectional.topEnd, - child: Text('•', style: style), width: width, padding: EdgeInsetsDirectional.only(end: 13.0), + child: Text('•', style: style), ); } } @@ -706,12 +706,12 @@ class __CheckboxState extends State<_Checkbox> { Widget build(BuildContext context) { return Container( alignment: AlignmentDirectional.topEnd, + width: widget.width, + padding: EdgeInsetsDirectional.only(end: 13.0), child: Checkbox( value: widget.isChecked, onChanged: _onCheckboxClicked, ), - width: widget.width, - padding: EdgeInsetsDirectional.only(end: 13.0), ); } } diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index e7f0975c..0da1e64f 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -158,7 +158,7 @@ class TextLine extends StatelessWidget { if (fontSize != null) { res = res.merge(TextStyle(fontSize: fontSize)); } else { - throw "Invalid size ${size.value}"; + throw 'Invalid size ${size.value}'; } } } @@ -166,13 +166,13 @@ class TextLine extends StatelessWidget { Attribute? color = textNode.style.attributes[Attribute.color.key]; if (color != null && color.value != null) { final textColor = stringToColor(color.value); - res = res.merge(new TextStyle(color: textColor)); + res = res.merge(TextStyle(color: textColor)); } Attribute? background = textNode.style.attributes[Attribute.background.key]; if (background != null && background.value != null) { final backgroundColor = stringToColor(background.value); - res = res.merge(new TextStyle(backgroundColor: backgroundColor)); + res = res.merge(TextStyle(backgroundColor: backgroundColor)); } return TextSpan(text: textNode.value, style: res); @@ -235,12 +235,12 @@ class EditableTextLine extends RenderObjectWidget { hasFocus, devicePixelRatio, _getPadding(), - this.color, + color, cursorCont); } @override - updateRenderObject( + void updateRenderObject( BuildContext context, covariant RenderEditableTextLine renderObject) { renderObject.setLine(line); renderObject.setPadding(_getPadding()); @@ -301,7 +301,7 @@ class RenderEditableTextLine extends RenderEditableBox { } } - setCursorCont(CursorCont c) { + void setCursorCont(CursorCont c) { if (cursorCont == c) { return; } @@ -309,7 +309,7 @@ class RenderEditableTextLine extends RenderEditableBox { markNeedsLayout(); } - setDevicePixelRatio(double d) { + void setDevicePixelRatio(double d) { if (devicePixelRatio == d) { return; } @@ -317,7 +317,7 @@ class RenderEditableTextLine extends RenderEditableBox { markNeedsLayout(); } - setEnableInteractiveSelection(bool val) { + void setEnableInteractiveSelection(bool val) { if (enableInteractiveSelection == val) { return; } @@ -326,7 +326,7 @@ class RenderEditableTextLine extends RenderEditableBox { markNeedsSemanticsUpdate(); } - setColor(Color c) { + void setColor(Color c) { if (color == c) { return; } @@ -337,7 +337,7 @@ class RenderEditableTextLine extends RenderEditableBox { } } - setTextSelection(TextSelection t) { + void setTextSelection(TextSelection t) { if (textSelection == t) { return; } @@ -361,7 +361,7 @@ class RenderEditableTextLine extends RenderEditableBox { } } - setTextDirection(TextDirection t) { + void setTextDirection(TextDirection t) { if (textDirection == t) { return; } @@ -370,7 +370,7 @@ class RenderEditableTextLine extends RenderEditableBox { markNeedsLayout(); } - setLine(Line l) { + void setLine(Line l) { if (line == l) { return; } @@ -379,7 +379,7 @@ class RenderEditableTextLine extends RenderEditableBox { markNeedsLayout(); } - setPadding(EdgeInsetsGeometry p) { + void setPadding(EdgeInsetsGeometry p) { assert(p.isNonNegative); if (padding == p) { return; @@ -389,11 +389,11 @@ class RenderEditableTextLine extends RenderEditableBox { markNeedsLayout(); } - setLeading(RenderBox? l) { + void setLeading(RenderBox? l) { _leading = _updateChild(_leading, l, TextLineSlot.LEADING); } - setBody(RenderContentProxyBox? b) { + void setBody(RenderContentProxyBox? b) { _body = _updateChild(_body, b, TextLineSlot.BODY) as RenderContentProxyBox?; } @@ -433,7 +433,7 @@ class RenderEditableTextLine extends RenderEditableBox { }).toList(growable: false); } - _resolvePadding() { + void _resolvePadding() { if (_resolvedPadding != null) { return; } @@ -536,7 +536,7 @@ class RenderEditableTextLine extends RenderEditableBox { double get cursorHeight => cursorCont.style.height ?? preferredLineHeight(TextPosition(offset: 0)); - _computeCaretPrototype() { + void _computeCaretPrototype() { switch (defaultTargetPlatform) { case TargetPlatform.iOS: case TargetPlatform.macOS: @@ -556,7 +556,7 @@ class RenderEditableTextLine extends RenderEditableBox { } @override - attach(covariant PipelineOwner owner) { + void attach(covariant PipelineOwner owner) { super.attach(owner); for (final child in _children) { child.attach(owner); @@ -568,7 +568,7 @@ class RenderEditableTextLine extends RenderEditableBox { } @override - detach() { + void detach() { super.detach(); for (RenderBox child in _children) { child.detach(); @@ -580,12 +580,12 @@ class RenderEditableTextLine extends RenderEditableBox { } @override - redepthChildren() { + void redepthChildren() { _children.forEach(redepthChild); } @override - visitChildren(RenderObjectVisitor visitor) { + void visitChildren(RenderObjectVisitor visitor) { _children.forEach(visitor); } @@ -722,7 +722,7 @@ class RenderEditableTextLine extends RenderEditableBox { ); @override - paint(PaintingContext context, Offset offset) { + void paint(PaintingContext context, Offset offset) { if (_leading != null) { final parentData = _leading!.parentData as BoxParentData; final effectiveOffset = offset + parentData.offset; @@ -760,7 +760,7 @@ class RenderEditableTextLine extends RenderEditableBox { } } - _paintSelection(PaintingContext context, Offset effectiveOffset) { + void _paintSelection(PaintingContext context, Offset effectiveOffset) { assert(_selectedRects != null); final paint = Paint()..color = color; for (final box in _selectedRects!) { @@ -768,7 +768,7 @@ class RenderEditableTextLine extends RenderEditableBox { } } - _paintCursor(PaintingContext context, Offset effectiveOffset) { + void _paintCursor(PaintingContext context, Offset effectiveOffset) { final position = TextPosition( offset: textSelection.extentOffset - line.getDocumentOffset(), affinity: textSelection.base.affinity, @@ -778,7 +778,7 @@ class RenderEditableTextLine extends RenderEditableBox { @override bool hitTestChildren(BoxHitTestResult result, {required Offset position}) { - return this._children.first.hitTest(result, position: position); + return _children.first.hitTest(result, position: position); } } @@ -795,12 +795,12 @@ class _TextLineElement extends RenderObjectElement { super.renderObject as RenderEditableTextLine; @override - visitChildren(ElementVisitor visitor) { + void visitChildren(ElementVisitor visitor) { _slotToChildren.values.forEach(visitor); } @override - forgetChild(Element child) { + void forgetChild(Element child) { assert(_slotToChildren.containsValue(child)); assert(child.slot is TextLineSlot); assert(_slotToChildren.containsKey(child.slot)); @@ -809,14 +809,14 @@ class _TextLineElement extends RenderObjectElement { } @override - mount(Element? parent, dynamic newSlot) { + void mount(Element? parent, dynamic newSlot) { super.mount(parent, newSlot); _mountChild(widget.leading, TextLineSlot.LEADING); _mountChild(widget.body, TextLineSlot.BODY); } @override - update(EditableTextLine newWidget) { + void update(EditableTextLine newWidget) { super.update(newWidget); assert(widget == newWidget); _updateChild(widget.leading, TextLineSlot.LEADING); @@ -824,14 +824,14 @@ class _TextLineElement extends RenderObjectElement { } @override - insertRenderObjectChild(RenderBox child, TextLineSlot? slot) { + void insertRenderObjectChild(RenderBox child, TextLineSlot? slot) { // assert(child is RenderBox); _updateRenderObject(child, slot); assert(renderObject.children.keys.contains(slot)); } @override - removeRenderObjectChild(RenderObject child, TextLineSlot? slot) { + void removeRenderObjectChild(RenderObject child, TextLineSlot? slot) { assert(child is RenderBox); assert(renderObject.children[slot!] == child); _updateRenderObject(null, slot); @@ -839,7 +839,7 @@ class _TextLineElement extends RenderObjectElement { } @override - moveRenderObjectChild(RenderObject child, dynamic oldSlot, dynamic newSlot) { + void moveRenderObjectChild(RenderObject child, dynamic oldSlot, dynamic newSlot) { throw UnimplementedError(); } diff --git a/pubspec.yaml b/pubspec.yaml index 7fb8925c..4c1e457f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: flutter_quill -description: Rich text editor (Demo App https://bulletjournal.us/home/index.html ). +description: A rich text editor. version: 1.1.2 #author: bulletjournal homepage: https://bulletjournal.us/home/index.html