Fix analysis issues (#966)

* chore: rename Selectable to SelectableMixin

* chore: add platforms to pubspec.yaml
This commit is contained in:
Lucas.Xu 2022-09-02 10:17:36 +08:00 committed by GitHub
parent 69e3aed6b5
commit 15ff2efcc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 38 additions and 32 deletions

View File

@ -11,7 +11,7 @@ import 'package:flutter/material.dart';
/// 2. create a class extends [NodeWidgetBuilder]
/// 3. override the function `Widget build(NodeWidgetContext<Node> context)`
/// and return a widget to render. The returned widget should be
/// a StatefulWidget and mixin with [Selectable].
/// a StatefulWidget and mixin with [SelectableMixin].
///
/// 4. override the getter `nodeValidator`
/// to verify the data structure in [Node].
@ -50,7 +50,8 @@ class ImageNodeWidget extends StatefulWidget {
State<ImageNodeWidget> createState() => _ImageNodeWidgetState();
}
class _ImageNodeWidgetState extends State<ImageNodeWidget> with Selectable {
class _ImageNodeWidgetState extends State<ImageNodeWidget>
with SelectableMixin {
bool isHovered = false;
Node get node => widget.node;
EditorState get editorState => widget.editorState;

View File

@ -31,7 +31,7 @@ class _NetworkImageNodeWidget extends StatefulWidget {
}
class __NetworkImageNodeWidgetState extends State<_NetworkImageNodeWidget>
with Selectable {
with SelectableMixin {
RenderBox get _renderBox => context.findRenderObject() as RenderBox;
@override

View File

@ -33,7 +33,7 @@ class LinkNodeWidget extends StatefulWidget {
}
class _YouTubeLinkNodeWidgetState extends State<LinkNodeWidget>
with Selectable {
with SelectableMixin {
Node get node => widget.node;
EditorState get editorState => widget.editorState;
String get src => widget.node.attributes['youtube_link'] as String;

View File

@ -1,7 +1,6 @@
import 'package:appflowy_editor/src/document/node.dart';
import './state_tree.dart';
import './node.dart';
/// [NodeIterator] is used to traverse the nodes in visual order.
class NodeIterator implements Iterator<Node> {

View File

@ -4,7 +4,6 @@ import 'dart:math';
import 'package:appflowy_editor/src/document/attributes.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import './attributes.dart';
// constant number: 2^53 - 1
const int _maxInt = 9007199254740991;

View File

@ -10,7 +10,8 @@ extension NodeExtensions on Node {
key?.currentContext?.findRenderObject()?.unwrapOrNull<RenderBox>();
BuildContext? get context => key?.currentContext;
Selectable? get selectable => key?.currentState?.unwrapOrNull<Selectable>();
SelectableMixin? get selectable =>
key?.currentState?.unwrapOrNull<SelectableMixin>();
bool inSelection(Selection selection) {
if (selection.start.path <= selection.end.path) {

View File

@ -32,7 +32,8 @@ class ImageNodeWidget extends StatefulWidget {
State<ImageNodeWidget> createState() => _ImageNodeWidgetState();
}
class _ImageNodeWidgetState extends State<ImageNodeWidget> with Selectable {
class _ImageNodeWidgetState extends State<ImageNodeWidget>
with SelectableMixin {
final _imageKey = GlobalKey();
double? _imageWidth;

View File

@ -42,7 +42,7 @@ class BulletedListTextNodeWidget extends StatefulWidget {
// customize
class _BulletedListTextNodeWidgetState extends State<BulletedListTextNodeWidget>
with Selectable, DefaultSelectable {
with SelectableMixin, DefaultSelectable {
@override
final iconKey = GlobalKey();
@ -51,8 +51,8 @@ class _BulletedListTextNodeWidgetState extends State<BulletedListTextNodeWidget>
final _iconRightPadding = 5.0;
@override
Selectable<StatefulWidget> get forward =>
_richTextKey.currentState as Selectable;
SelectableMixin<StatefulWidget> get forward =>
_richTextKey.currentState as SelectableMixin;
@override
Widget build(BuildContext context) {

View File

@ -40,7 +40,7 @@ class CheckboxNodeWidget extends StatefulWidget {
}
class _CheckboxNodeWidgetState extends State<CheckboxNodeWidget>
with Selectable, DefaultSelectable {
with SelectableMixin, DefaultSelectable {
@override
final iconKey = GlobalKey();
@ -49,8 +49,8 @@ class _CheckboxNodeWidgetState extends State<CheckboxNodeWidget>
final _iconRightPadding = 5.0;
@override
Selectable<StatefulWidget> get forward =>
_richTextKey.currentState as Selectable;
SelectableMixin<StatefulWidget> get forward =>
_richTextKey.currentState as SelectableMixin;
@override
Widget build(BuildContext context) {

View File

@ -4,7 +4,7 @@ import 'package:appflowy_editor/src/render/selection/selectable.dart';
import 'package:flutter/material.dart';
mixin DefaultSelectable {
Selectable get forward;
SelectableMixin get forward;
GlobalKey? get iconKey;

View File

@ -42,7 +42,7 @@ class FlowyRichText extends StatefulWidget {
State<FlowyRichText> createState() => _FlowyRichTextState();
}
class _FlowyRichTextState extends State<FlowyRichText> with Selectable {
class _FlowyRichTextState extends State<FlowyRichText> with SelectableMixin {
var _textKey = GlobalKey();
final _placeholderTextKey = GlobalKey();

View File

@ -39,7 +39,7 @@ class HeadingTextNodeWidget extends StatefulWidget {
// customize
class _HeadingTextNodeWidgetState extends State<HeadingTextNodeWidget>
with Selectable, DefaultSelectable {
with SelectableMixin, DefaultSelectable {
@override
GlobalKey? get iconKey => null;
@ -47,8 +47,8 @@ class _HeadingTextNodeWidgetState extends State<HeadingTextNodeWidget>
final _topPadding = 5.0;
@override
Selectable<StatefulWidget> get forward =>
_richTextKey.currentState as Selectable;
SelectableMixin<StatefulWidget> get forward =>
_richTextKey.currentState as SelectableMixin;
@override
Offset get baseOffset {

View File

@ -42,7 +42,7 @@ class NumberListTextNodeWidget extends StatefulWidget {
// customize
class _NumberListTextNodeWidgetState extends State<NumberListTextNodeWidget>
with Selectable, DefaultSelectable {
with SelectableMixin, DefaultSelectable {
@override
final iconKey = GlobalKey();
@ -51,8 +51,8 @@ class _NumberListTextNodeWidgetState extends State<NumberListTextNodeWidget>
final _iconRightPadding = 5.0;
@override
Selectable<StatefulWidget> get forward =>
_richTextKey.currentState as Selectable;
SelectableMixin<StatefulWidget> get forward =>
_richTextKey.currentState as SelectableMixin;
@override
Widget build(BuildContext context) {

View File

@ -41,7 +41,7 @@ class QuotedTextNodeWidget extends StatefulWidget {
// customize
class _QuotedTextNodeWidgetState extends State<QuotedTextNodeWidget>
with Selectable, DefaultSelectable {
with SelectableMixin, DefaultSelectable {
@override
final iconKey = GlobalKey();
@ -50,8 +50,8 @@ class _QuotedTextNodeWidgetState extends State<QuotedTextNodeWidget>
final _iconRightPadding = 5.0;
@override
Selectable<StatefulWidget> get forward =>
_richTextKey.currentState as Selectable;
SelectableMixin<StatefulWidget> get forward =>
_richTextKey.currentState as SelectableMixin;
@override
Widget build(BuildContext context) {

View File

@ -40,15 +40,15 @@ class RichTextNodeWidget extends StatefulWidget {
// customize
class _RichTextNodeWidgetState extends State<RichTextNodeWidget>
with Selectable, DefaultSelectable {
with SelectableMixin, DefaultSelectable {
@override
GlobalKey? get iconKey => null;
final _richTextKey = GlobalKey(debugLabel: 'rich_text');
@override
Selectable<StatefulWidget> get forward =>
_richTextKey.currentState as Selectable;
SelectableMixin<StatefulWidget> get forward =>
_richTextKey.currentState as SelectableMixin;
@override
Widget build(BuildContext context) {

View File

@ -2,12 +2,12 @@ import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:flutter/material.dart';
/// [Selectable] is used for the editor to calculate the position
/// [SelectableMixin] is used for the editor to calculate the position
/// and size of the selection.
///
/// The widget returned by NodeWidgetBuilder must be with [Selectable],
/// The widget returned by NodeWidgetBuilder must be with [SelectableMixin],
/// otherwise the [AppFlowySelectionService] will not work properly.
mixin Selectable<T extends StatefulWidget> on State<T> {
mixin SelectableMixin<T extends StatefulWidget> on State<T> {
/// Returns the [Selection] surrounded by start and end
/// in current widget.
///

View File

@ -510,7 +510,7 @@ class _AppFlowySelectionState extends State<AppFlowySelection>
editorState.service.scrollService?.enable();
}
Rect _transformRectToGlobal(Selectable selectable, Rect r) {
Rect _transformRectToGlobal(SelectableMixin selectable, Rect r) {
final Offset topLeft = selectable.localToGlobal(Offset(r.left, r.top));
return Rect.fromLTWH(topLeft.dx, topLeft.dy, r.width, r.height);
}

View File

@ -3,6 +3,11 @@ description: A highly customizable rich-text editor for Flutter
version: 0.0.3
homepage: https://github.com/AppFlowy-IO/AppFlowy
platforms:
linux:
macos:
windows:
environment:
sdk: ">=2.17.0 <3.0.0"
flutter: ">=1.17.0"