fix: make sure the state is implemnt selectable, otherwise return.

This commit is contained in:
Lucas.Xu 2022-07-22 10:43:20 +08:00
parent 6c811aef72
commit e16444f88e

View File

@ -110,8 +110,10 @@ class _FlowySelectionWidgetState extends State<FlowySelectionWidget>
} }
for (final node in nodes) { for (final node in nodes) {
final selectable = node.key?.currentState as Selectable?; if (node.key?.currentState is! Selectable) {
if (selectable != null) { continue;
}
final selectable = node.key?.currentState as Selectable;
final selectionRects = selectable.getSelectionRectsInSelection( final selectionRects = selectable.getSelectionRectsInSelection(
panStartOffset!, panEndOffset!); panStartOffset!, panEndOffset!);
for (final rect in selectionRects) { for (final rect in selectionRects) {
@ -126,7 +128,6 @@ class _FlowySelectionWidgetState extends State<FlowySelectionWidget>
selectionOverlays.add(overlay); selectionOverlays.add(overlay);
} }
} }
}
Overlay.of(context)?.insertAll(selectionOverlays); Overlay.of(context)?.insertAll(selectionOverlays);
} }
@ -146,8 +147,10 @@ class _FlowySelectionWidgetState extends State<FlowySelectionWidget>
} }
final selectedNode = nodes.first; final selectedNode = nodes.first;
final selectable = selectedNode.key?.currentState as Selectable?; if (selectedNode.key?.currentState is! Selectable) {
if (selectable != null) { return;
}
final selectable = selectedNode.key?.currentState as Selectable;
final rect = selectable.getCursorRect(tapOffset!); final rect = selectable.getCursorRect(tapOffset!);
final cursor = OverlayEntry( final cursor = OverlayEntry(
builder: ((context) => Positioned.fromRect( builder: ((context) => Positioned.fromRect(
@ -158,7 +161,6 @@ class _FlowySelectionWidgetState extends State<FlowySelectionWidget>
)), )),
); );
selectionOverlays.add(cursor); selectionOverlays.add(cursor);
}
Overlay.of(context)?.insertAll(selectionOverlays); Overlay.of(context)?.insertAll(selectionOverlays);
} }
@ -183,12 +185,6 @@ class _FlowySelectionWidgetState extends State<FlowySelectionWidget>
final tapOffset = this.tapOffset; final tapOffset = this.tapOffset;
if (tapOffset != null) {} if (tapOffset != null) {}
if (node.parent != null && node.key != null) {
if (isNodeInOffset(node, offset)) {
return node;
}
}
for (final child in node.children) { for (final child in node.children) {
final result = computeSelectedNodeByTap(child, offset); final result = computeSelectedNodeByTap(child, offset);
if (result != null) { if (result != null) {
@ -196,6 +192,12 @@ class _FlowySelectionWidgetState extends State<FlowySelectionWidget>
} }
} }
if (node.parent != null && node.key != null) {
if (isNodeInOffset(node, offset)) {
return node;
}
}
return null; return null;
} }