_visibility in TextSelection is not nullable

pull/630/head
X Code 3 years ago
parent 5b7d865074
commit b3c627f7a9
  1. 14
      lib/src/widgets/text_selection.dart

@ -430,12 +430,14 @@ class _TextSelectionHandleOverlay extends StatefulWidget {
_TextSelectionHandleOverlayState createState() => _TextSelectionHandleOverlayState createState() =>
_TextSelectionHandleOverlayState(); _TextSelectionHandleOverlayState();
ValueListenable<bool>? get _visibility { ValueListenable<bool> get _visibility {
switch (position) { switch (position) {
case _TextSelectionHandlePosition.START: case _TextSelectionHandlePosition.START:
return renderObject!.selectionStartInViewport; return renderObject!.selectionStartInViewport;
case _TextSelectionHandlePosition.END: case _TextSelectionHandlePosition.END:
return renderObject!.selectionEndInViewport; return renderObject!.selectionEndInViewport;
default:
throw 'Invalid position';
} }
} }
} }
@ -457,11 +459,11 @@ class _TextSelectionHandleOverlayState
duration: const Duration(milliseconds: 150), vsync: this); duration: const Duration(milliseconds: 150), vsync: this);
_handleVisibilityChanged(); _handleVisibilityChanged();
widget._visibility!.addListener(_handleVisibilityChanged); widget._visibility.addListener(_handleVisibilityChanged);
} }
void _handleVisibilityChanged() { void _handleVisibilityChanged() {
if (widget._visibility!.value) { if (widget._visibility.value) {
_controller.forward(); _controller.forward();
} else { } else {
_controller.reverse(); _controller.reverse();
@ -471,14 +473,14 @@ class _TextSelectionHandleOverlayState
@override @override
void didUpdateWidget(_TextSelectionHandleOverlay oldWidget) { void didUpdateWidget(_TextSelectionHandleOverlay oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
oldWidget._visibility!.removeListener(_handleVisibilityChanged); oldWidget._visibility.removeListener(_handleVisibilityChanged);
_handleVisibilityChanged(); _handleVisibilityChanged();
widget._visibility!.addListener(_handleVisibilityChanged); widget._visibility.addListener(_handleVisibilityChanged);
} }
@override @override
void dispose() { void dispose() {
widget._visibility!.removeListener(_handleVisibilityChanged); widget._visibility.removeListener(_handleVisibilityChanged);
_controller.dispose(); _controller.dispose();
super.dispose(); super.dispose();
} }

Loading…
Cancel
Save