Skip to content

Commit

Permalink
fix: flutter analyze and dart lint
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed May 22, 2023
1 parent 6851f04 commit 82593b3
Show file tree
Hide file tree
Showing 28 changed files with 37 additions and 210 deletions.
6 changes: 6 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ linter:
- use_decorated_box

analyzer:
errors:
deprecated_member_use_from_same_package: ignore
exclude:
- lib/src/l10n/**
# Remove the below directory until migration is complete.
- example/**
- test/**
- lib/src/service/**
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/block_component/base_component/widget/nested_list_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/block_component/base_component/insert_newline_in_type_command.dart';
import 'package:appflowy_editor/src/editor/block_component/base_component/markdown_format_helper.dart';

/// Convert '* ' to bulleted list
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/block_component/base_component/markdown_format_helper.dart';

/// Convert '# ' to bulleted list
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/block_component/image_block_component/image_block_component.dart';
import 'package:flutter/material.dart';

void showImageMenu(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/block_component/base_component/widget/nested_list_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/block_component/base_component/markdown_format_helper.dart';

final _numberRegex = RegExp(r'^(\d+)\.');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/block_component/base_component/markdown_format_helper.dart';

const _doubleQuote = '"';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/block_component/base_component/widget/nested_list_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/block_component/base_component/markdown_format_helper.dart';

/// Convert '[] ' to unchecked todo list
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class TextInputService {
onNonTextUpdate;
Future<void> Function(TextInputAction action) onPerformAction;

TextRange? composingTextRange;
TextRange? get composingTextRange;
bool get attached;

void updateCaretPosition(Size size, Matrix4 transform, Rect rect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class DesktopScrollService extends StatefulWidget {

class _DesktopScrollServiceState extends State<DesktopScrollService>
implements AppFlowyScrollService {
bool _scrollEnabled = true;

@override
double get dy => widget.scrollController.position.pixels;

Expand Down Expand Up @@ -76,13 +74,11 @@ class _DesktopScrollServiceState extends State<DesktopScrollService>

@override
void disable() {
_scrollEnabled = false;
Log.scroll.debug('disable scroll service');
}

@override
void enable() {
_scrollEnabled = true;
Log.scroll.debug('enable scroll service');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ class _MobileSelectionServiceWidgetState
@override
List<Node> currentSelectedNodes = [];

/// Pan
Offset? _panStartOffset;
double? _panStartScrollDy;

late EditorState editorState = Provider.of<EditorState>(
context,
listen: false,
Expand Down Expand Up @@ -230,9 +226,6 @@ class _MobileSelectionServiceWidgetState

editorState.service.scrollService?.stopAutoScroll();

// clear old state.
_panStartOffset = null;

final position = getPositionInOffset(details.globalPosition);
if (position == null) {
return;
Expand Down Expand Up @@ -289,44 +282,6 @@ class _MobileSelectionServiceWidgetState
_showContextMenu(details);
}

void _onPanStart(DragStartDetails details) {
clearSelection();

_panStartOffset = details.globalPosition.translate(-3.0, 0);
_panStartScrollDy = editorState.service.scrollService?.dy;
}

void _onPanUpdate(DragUpdateDetails details) {
if (_panStartOffset == null || _panStartScrollDy == null) {
return;
}

final panEndOffset = details.globalPosition;
final dy = editorState.service.scrollService?.dy;
final panStartOffset = dy == null
? _panStartOffset!
: _panStartOffset!.translate(0, _panStartScrollDy! - dy);

final first = getNodeInOffset(panStartOffset)?.selectable;
final last = getNodeInOffset(panEndOffset)?.selectable;

// compute the selection in range.
if (first != null && last != null) {
Log.selection.debug('first = $first, last = $last');
final start =
first.getSelectionInRange(panStartOffset, panEndOffset).start;
final end = last.getSelectionInRange(panStartOffset, panEndOffset).end;
final selection = Selection(start: start, end: end);
updateSelection(selection);
}

_showDebugLayerIfNeeded(offset: panEndOffset);
}

void _onPanEnd(DragEndDetails details) {
// do nothing
}

void _updateSelectionAreas(Selection selection) {
final nodes = getNodesInSelection(selection);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/shortcuts/character_shortcut_events/format_by_wrapping_with_double_character/format_bold.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/shortcuts/character_shortcut_events/format_by_wrapping_with_double_character/format_strikethrough.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/shortcuts/character_shortcut_events/format_by_wrapping_with_single_character/format_code.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/shortcuts/character_shortcut_events/format_by_wrapping_with_single_character/format_italic.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/shortcuts/character_shortcut_events/format_by_wrapping_with_single_character/format_strikethrough.dart';

// Include all the shortcut(formatting) events triggered by wrapping text with double characters.
// 1. double asterisk to bold -> **abc**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Future<bool> _showSlashMenu(
}

// show the slash menu
{
() {
// this code is copied from the the old editor.
// TODO: refactor this code
final context = editorState.getNodeAtPath(selection.start.path)?.context;
Expand All @@ -76,7 +76,7 @@ Future<bool> _showSlashMenu(
);
_selectionMenuService?.show();
}
}
}();

return true;
}
2 changes: 1 addition & 1 deletion lib/src/editor/util/color_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ extension ColorExtension on String {

extension HexExtension on Color {
String toHex() {
return '${value.toRadixString(16)}';
return value.toRadixString(16);
}
}
15 changes: 15 additions & 0 deletions lib/src/editor/util/property_notifier.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter/material.dart';

/// [PropertyValueNotifier] is a subclass of [ValueNotifier].
///
/// The difference is that [PropertyValueNotifier] will notify listeners even
/// when the value is the same as the previous value.
class PropertyValueNotifier<T> extends ValueNotifier<T> {
PropertyValueNotifier(T value) : super(value);

@override
// ignore: unnecessary_overrides
void notifyListeners() {
super.notifyListeners();
}
}
1 change: 1 addition & 0 deletions lib/src/editor/util/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export 'raw_keyboard_extension.dart';
export 'platform_extension.dart';
export 'delta_util.dart';
export 'color_util.dart';
export 'property_notifier.dart';
30 changes: 2 additions & 28 deletions lib/src/editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class EditorState {
late EditorStyle editorStyle;

/// The selection notifier of the editor.
final ValueNotifier<Selection?> selectionNotifier =
ValueNotifier<Selection?>(null);
final PropertyValueNotifier<Selection?> selectionNotifier =
PropertyValueNotifier<Selection?>(null);

/// The selection of the editor.
Selection? get selection => selectionNotifier.value;
Expand Down Expand Up @@ -216,8 +216,6 @@ class EditorState {
_selectionUpdateReason = SelectionUpdateReason.transaction;
selection = transaction.afterSelection;
_selectionUpdateReason = SelectionUpdateReason.uiEvent;
// if the selection is not changed, we still need to notify the listeners.
selectionNotifier.notifyListeners();
}

// TODO: execute this line after the UI has been updated.
Expand Down Expand Up @@ -357,28 +355,4 @@ class EditorState {
document.updateText(op.path, op.delta);
}
}

void _applyRules(int maximumRuleApplyLoop) {
// Set a maximum count to prevent a dead loop.
if (maximumRuleApplyLoop >= 5 || disableRules) {
return;
}

// Rules
_insureLastNodeEditable(transaction);

if (transaction.operations.isNotEmpty) {
apply(
transaction,
withUpdateSelection: false,
);
}
}

void _insureLastNodeEditable(Transaction tr) {
if (document.root.children.isEmpty ||
document.root.children.last.id != 'text') {
tr.insertNode([document.root.children.length], TextNode.empty());
}
}
}
1 change: 0 additions & 1 deletion lib/src/render/rich_text/checkbox_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class _CheckboxNodeWidgetState extends State<CheckboxNodeWidget>

@override
Widget buildWithSingle(BuildContext context) {
final check = widget.textNode.attributes.check;
return Padding(
padding: padding,
child: Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ShortcutEventHandler backspaceEventHandler = (editorState, event) {
transaction
..updateNode(textNode, {
BuiltInAttributeKey.subtype: null,
textNode.subtype!: null,
textNode.subtype: null,
})
..afterSelection = Selection.collapsed(
Position(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler =
// If selection is collapsed and position.start.offset == 0,
// insert a empty text node before.
if (selection.isCollapsed && selection.start.offset == 0) {
if (textNode.toPlainText().isEmpty && textNode.subtype != null) {
if (textNode.toPlainText().isEmpty) {
final path =
textNode.path.length > 1 ? [++textNode.path.first] : textNode.path;

Expand All @@ -94,7 +94,7 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler =
transaction
..updateNode(textNode, {
BuiltInAttributeKey.subtype: null,
textNode.subtype!: null,
textNode.subtype: null,
})
..afterSelection = afterSelection;
}
Expand Down Expand Up @@ -202,8 +202,7 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler =
Attributes _attributesFromPreviousLine(TextNode textNode) {
final prevAttributes = textNode.attributes;
final subType = textNode.subtype;
if (subType == null ||
subType == BuiltInAttributeKey.heading ||
if (subType == BuiltInAttributeKey.heading ||
subType == BuiltInAttributeKey.quote) {
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/service/render_plugin_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class AppFlowyRenderPlugin extends AppFlowyRenderPluginService {
Widget buildPluginWidget(NodeWidgetContext context) {
final node = context.node;
final name =
node.subtype == null ? node.type : '${node.type}/${node.subtype!}';
node.subtype == null ? node.type : '${node.type}/${node.subtype}';
final builder = _builders[name];
if (builder != null && builder.nodeValidator(node)) {
return _autoUpdateNodeWidget(builder, context);
Expand Down
Loading

0 comments on commit 82593b3

Please sign in to comment.