diff --git a/.github/workflows/fleather.yml b/.github/workflows/fleather.yml index c1bfe574..f4809bb0 100644 --- a/.github/workflows/fleather.yml +++ b/.github/workflows/fleather.yml @@ -28,10 +28,9 @@ jobs: working-directory: ./packages/parchment run: dart format --output=none --set-exit-if-changed . - # Consider passing '--fatal-infos' for slightly stricter analysis. - # - name: Parchment - Analyze project source - # working-directory: ./packages/parchment - # run: dart analyze + - name: Parchment - Analyze project source + working-directory: ./packages/parchment + run: dart analyze --fatal-infos - name: Parchment - Run tests working-directory: ./packages/parchment @@ -51,10 +50,9 @@ jobs: working-directory: ./packages/fleather run: dart format --output=none --set-exit-if-changed . - # Consider passing '--fatal-infos' for slightly stricter analysis. - # - name: Fleather - Analyze project source - # working-directory: ./packages/fleather - # run: dart analyze + - name: Fleather - Analyze project source + working-directory: ./packages/fleather + run: flutter analyze --fatal-infos - name: Fleather - Run tests working-directory: ./packages/fleather diff --git a/packages/fleather/lib/src/rendering/editable_box.dart b/packages/fleather/lib/src/rendering/editable_box.dart index 42de4fbf..2e1a6a2b 100644 --- a/packages/fleather/lib/src/rendering/editable_box.dart +++ b/packages/fleather/lib/src/rendering/editable_box.dart @@ -328,12 +328,6 @@ class RenderEditableContainerBox extends RenderBox assert(size.isFinite); } - @override - void debugFillProperties(DiagnosticPropertiesBuilder properties) { - super.debugFillProperties(properties); -// properties.add(EnumProperty('axisDirection', axisDirection)); - } - double _getIntrinsicCrossAxis(_ChildSizingFunction childSize) { var extent = 0.0; var child = firstChild; diff --git a/packages/fleather/lib/src/rendering/editable_text_block.dart b/packages/fleather/lib/src/rendering/editable_text_block.dart index c28ea69e..468f7b1c 100644 --- a/packages/fleather/lib/src/rendering/editable_text_block.dart +++ b/packages/fleather/lib/src/rendering/editable_text_block.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'package:parchment/parchment.dart'; diff --git a/packages/fleather/lib/src/rendering/editor.dart b/packages/fleather/lib/src/rendering/editor.dart index e8beb448..8e6e2415 100644 --- a/packages/fleather/lib/src/rendering/editor.dart +++ b/packages/fleather/lib/src/rendering/editor.dart @@ -5,7 +5,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; -import 'package:parchment/parchment.dart'; import '../../fleather.dart'; import '../widgets/selection_utils.dart'; @@ -991,8 +990,7 @@ class RenderEditor extends RenderEditableContainerBox } } -class FleatherVerticalCaretMovementRun - extends BidirectionalIterator { +class FleatherVerticalCaretMovementRun extends Iterator { FleatherVerticalCaretMovementRun._( this._editor, this._currentTextPosition, @@ -1013,7 +1011,9 @@ class FleatherVerticalCaretMovementRun return true; } - @override + /// Move back to the previous element. + /// + /// Returns true and updates [current] if successful. bool movePrevious() { _currentTextPosition = _editor.getTextPositionAbove(_currentTextPosition); return true; diff --git a/packages/fleather/lib/src/widgets/cursor.dart b/packages/fleather/lib/src/widgets/cursor.dart index 646aeda9..507a730a 100644 --- a/packages/fleather/lib/src/widgets/cursor.dart +++ b/packages/fleather/lib/src/widgets/cursor.dart @@ -94,8 +94,15 @@ class CursorStyle { } @override - int get hashCode => hashValues(color, backgroundColor, width, height, radius, - offset, opacityAnimates, paintAboveText); + int get hashCode => + color.hashCode ^ + backgroundColor.hashCode ^ + width.hashCode ^ + height.hashCode ^ + radius.hashCode ^ + offset.hashCode ^ + opacityAnimates.hashCode ^ + paintAboveText.hashCode; } /// Controls cursor of an editable widget. diff --git a/packages/fleather/lib/src/widgets/editor.dart b/packages/fleather/lib/src/widgets/editor.dart index daa10d12..c28dbd30 100644 --- a/packages/fleather/lib/src/widgets/editor.dart +++ b/packages/fleather/lib/src/widgets/editor.dart @@ -448,6 +448,7 @@ class _FleatherEditorSelectionGestureDetectorBuilder } break; case PointerDeviceKind.touch: + case PointerDeviceKind.trackpad: case PointerDeviceKind.unknown: // On macOS/iOS/iPadOS a touch tap places the cursor at the edge // of the word. @@ -836,7 +837,6 @@ class RawEditorState extends EditorState void copySelection(SelectionChangedCause cause) { final TextSelection selection = textEditingValue.selection; final String text = textEditingValue.text; - assert(selection != null); if (selection.isCollapsed) { return; } @@ -875,7 +875,6 @@ class RawEditorState extends EditorState } final TextSelection selection = textEditingValue.selection; final String text = textEditingValue.text; - assert(selection != null); if (selection.isCollapsed) { return; } @@ -894,7 +893,6 @@ class RawEditorState extends EditorState return; } final TextSelection selection = textEditingValue.selection; - assert(selection != null); if (!selection.isValid) { return; } @@ -1587,13 +1585,6 @@ class _Editor extends MultiChildRenderObjectWidget { renderObject.padding = padding; renderObject.maxContentWidth = maxContentWidth; } - - @override - void debugFillProperties(DiagnosticPropertiesBuilder properties) { - super.debugFillProperties(properties); - // TODO -// properties.add(EnumProperty('direction', direction)); - } } /// An interface for retriving the logical text boundary (left-closed-right-open) @@ -1635,6 +1626,8 @@ abstract class _TextBoundary { // ----------------------------- Text Boundaries ----------------------------- +// TODO: Check whether to use it or remove it +// ignore: unused_element class _CodeUnitBoundary extends _TextBoundary { const _CodeUnitBoundary(this.textEditingValue); @@ -1986,7 +1979,7 @@ class _UpdateTextSelectionAction final bool 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( @@ -2000,7 +1993,7 @@ class _UpdateTextSelectionAction collapseSelection) { return Actions.invoke( context!, - UpdateSelectionIntent(state.textEditingValue, _collapse(selection), + UpdateSelectionIntent(state.textEditingValue, collapse(selection), SelectionChangedCause.keyboard), ); } @@ -2017,7 +2010,7 @@ class _UpdateTextSelectionAction return Actions.invoke( context!, UpdateSelectionIntent(state.textEditingValue, - _collapse(textBoundarySelection), SelectionChangedCause.keyboard), + collapse(textBoundarySelection), SelectionChangedCause.keyboard), ); } diff --git a/packages/fleather/lib/src/widgets/editor_toolbar.dart b/packages/fleather/lib/src/widgets/editor_toolbar.dart index 81c2d177..6d2a4866 100644 --- a/packages/fleather/lib/src/widgets/editor_toolbar.dart +++ b/packages/fleather/lib/src/widgets/editor_toolbar.dart @@ -55,7 +55,7 @@ class LinkStyleButton extends StatefulWidget { }) : super(key: key); @override - _LinkStyleButtonState createState() => _LinkStyleButtonState(); + State createState() => _LinkStyleButtonState(); } class _LinkStyleButtonState extends State { @@ -192,7 +192,7 @@ class ToggleStyleButton extends StatefulWidget { }) : super(key: key); @override - _ToggleStyleButtonState createState() => _ToggleStyleButtonState(); + State createState() => _ToggleStyleButtonState(); } class _ToggleStyleButtonState extends State { @@ -298,7 +298,7 @@ class SelectHeadingStyleButton extends StatefulWidget { : super(key: key); @override - _SelectHeadingStyleButtonState createState() => + State createState() => _SelectHeadingStyleButtonState(); } @@ -408,7 +408,7 @@ class IndentationButton extends StatefulWidget { : super(key: key); @override - _IndentationButtonState createState() => _IndentationButtonState(); + State createState() => _IndentationButtonState(); } class _IndentationButtonState extends State { @@ -683,7 +683,7 @@ class FleatherToolbar extends StatefulWidget implements PreferredSizeWidget { } @override - _FleatherToolbarState createState() => _FleatherToolbarState(); + State createState() => _FleatherToolbarState(); @override Size get preferredSize => const Size.fromHeight(kToolbarHeight); @@ -768,7 +768,7 @@ class FLDropdownButton extends StatefulWidget { }) : super(key: key); @override - _FLDropdownButtonState createState() => _FLDropdownButtonState(); + State> createState() => _FLDropdownButtonState(); } class _FLDropdownButtonState extends State> { diff --git a/packages/fleather/lib/src/widgets/text_selection.dart b/packages/fleather/lib/src/widgets/text_selection.dart index 9155ee41..f56b6de3 100644 --- a/packages/fleather/lib/src/widgets/text_selection.dart +++ b/packages/fleather/lib/src/widgets/text_selection.dart @@ -416,8 +416,6 @@ class _TextSelectionHandleOverlay extends StatefulWidget { class _TextSelectionHandleOverlayState extends State<_TextSelectionHandleOverlay> with SingleTickerProviderStateMixin { - late Offset _dragPosition; - late AnimationController _controller; Animation get _opacity => _controller.view; @@ -456,17 +454,7 @@ class _TextSelectionHandleOverlayState super.dispose(); } - void _handleDragStart(DragStartDetails details) { - final textPosition = widget.position == _TextSelectionHandlePosition.start - ? widget.selection.base - : widget.selection.extent; - final lineHeight = widget.renderObject.preferredLineHeight(textPosition); - final Size handleSize = widget.selectionControls!.getHandleSize(lineHeight); - _dragPosition = details.globalPosition + Offset(0.0, -handleSize.height); - } - void _handleDragUpdate(DragUpdateDetails details) { - _dragPosition += details.delta; final TextPosition position = widget.renderObject.getPositionForOffset(details.globalPosition); if (widget.selection.isCollapsed) { @@ -578,7 +566,6 @@ class _TextSelectionHandleOverlayState child: GestureDetector( behavior: HitTestBehavior.translucent, dragStartBehavior: widget.dragStartBehavior, - onPanStart: _handleDragStart, onPanUpdate: _handleDragUpdate, onTap: _handleTap, child: Padding( diff --git a/packages/fleather/lib/src/widgets/theme.dart b/packages/fleather/lib/src/widgets/theme.dart index 2b9eb34e..bb70e0ca 100644 --- a/packages/fleather/lib/src/widgets/theme.dart +++ b/packages/fleather/lib/src/widgets/theme.dart @@ -139,7 +139,7 @@ class FleatherThemeData { final inlineCodeStyle = TextStyle( fontSize: 14, - color: themeData.colorScheme.primaryVariant.withOpacity(0.8), + color: themeData.colorScheme.primaryContainer.withOpacity(0.8), fontFamily: fontFamily, ); @@ -163,7 +163,7 @@ class FleatherThemeData { ), ), link: TextStyle( - color: themeData.colorScheme.primaryVariant, + color: themeData.colorScheme.primaryContainer, decoration: TextDecoration.underline, ), paragraph: TextBlockTheme( diff --git a/packages/fleather/test/widgets/editor_test.dart b/packages/fleather/test/widgets/editor_test.dart index 9db6949f..1cec4eae 100644 --- a/packages/fleather/test/widgets/editor_test.dart +++ b/packages/fleather/test/widgets/editor_test.dart @@ -198,5 +198,6 @@ void prepareClipboard() { if (message.method == 'Clipboard.hasStrings') { return Future.value({'value': true}); } + return null; }); } diff --git a/packages/parchment/lib/src/convert/markdown.dart b/packages/parchment/lib/src/convert/markdown.dart index 1276d887..25964b76 100644 --- a/packages/parchment/lib/src/convert/markdown.dart +++ b/packages/parchment/lib/src/convert/markdown.dart @@ -37,7 +37,7 @@ class _ParchmentMarkdownEncoder extends Converter { var currentInlineStyle = ParchmentStyle(); var currentBlockLines = []; - void _handleBlock(ParchmentAttribute? blockStyle) { + void handleBlock(ParchmentAttribute? blockStyle) { if (currentBlockLines.isEmpty) { return; // Empty block } @@ -60,19 +60,19 @@ class _ParchmentMarkdownEncoder extends Converter { buffer.writeln(); } - void _handleSpan(String text, Map? attributes) { + void handleSpan(String text, Map? attributes) { final style = ParchmentStyle.fromJson(attributes); currentInlineStyle = _writeInline(lineBuffer, text, style, currentInlineStyle); } - void _handleLine(Map? attributes) { + void handleLine(Map? attributes) { final style = ParchmentStyle.fromJson(attributes); final lineBlock = style.get(ParchmentAttribute.block); if (lineBlock == currentBlockStyle) { currentBlockLines.add(_writeLine(lineBuffer.toString(), style)); } else { - _handleBlock(currentBlockStyle); + handleBlock(currentBlockStyle); currentBlockLines.clear(); currentBlockLines.add(_writeLine(lineBuffer.toString(), style)); @@ -86,18 +86,18 @@ class _ParchmentMarkdownEncoder extends Converter { final opText = op.data is String ? op.data as String : ''; final lf = opText.indexOf('\n'); if (lf == -1) { - _handleSpan(op.data as String, op.attributes); + handleSpan(op.data as String, op.attributes); } else { var span = StringBuffer(); for (var i = 0; i < opText.length; i++) { if (opText.codeUnitAt(i) == 0x0A) { if (span.isNotEmpty) { // Write the span if it's not empty. - _handleSpan(span.toString(), op.attributes); + handleSpan(span.toString(), op.attributes); } // Close any open inline styles. - _handleSpan('', null); - _handleLine(op.attributes); + handleSpan('', null); + handleLine(op.attributes); span.clear(); } else { span.writeCharCode(opText.codeUnitAt(i)); @@ -105,11 +105,11 @@ class _ParchmentMarkdownEncoder extends Converter { } // Remaining span if (span.isNotEmpty) { - _handleSpan(span.toString(), op.attributes); + handleSpan(span.toString(), op.attributes); } } } - _handleBlock(currentBlockStyle); // Close the last block + handleBlock(currentBlockStyle); // Close the last block return buffer.toString(); } diff --git a/packages/parchment/lib/src/document/line.dart b/packages/parchment/lib/src/document/line.dart index 1e51b132..81b825e6 100644 --- a/packages/parchment/lib/src/document/line.dart +++ b/packages/parchment/lib/src/document/line.dart @@ -5,9 +5,9 @@ import 'dart:math' as math; import 'package:quill_delta/quill_delta.dart'; -import 'embeds.dart'; import 'attributes.dart'; import 'block.dart'; +import 'embeds.dart'; import 'leaf.dart'; import 'node.dart'; @@ -115,7 +115,7 @@ class LineNode extends ContainerNode var result = ParchmentStyle(); final excluded = {}; - void _handle(ParchmentStyle style) { + void handle(ParchmentStyle style) { if (result.isEmpty) { excluded.addAll(style.values); } else { @@ -137,7 +137,7 @@ class LineNode extends ContainerNode var pos = node.length - data.offset; while (!node!.isLast && pos < local) { node = node.next as LeafNode; - _handle(node.style); + handle(node.style); pos += node.length; } } @@ -151,7 +151,7 @@ class LineNode extends ContainerNode final remaining = length - local; if (remaining > 0) { final rest = nextLine!.collectStyle(0, remaining); - _handle(rest); + handle(rest); } return result;