diff --git a/packages/flutter/lib/src/widgets/text_selection.dart b/packages/flutter/lib/src/widgets/text_selection.dart index c0d699aae8..0ed6718284 100644 --- a/packages/flutter/lib/src/widgets/text_selection.dart +++ b/packages/flutter/lib/src/widgets/text_selection.dart @@ -1025,7 +1025,7 @@ class SelectionOverlay { context: context, below: magnifierConfiguration.shouldDisplayHandlesInMagnifier ? null - : _handles?.first, + : _handles?.start, builder: (_) => builtMagnifier); } @@ -1333,7 +1333,7 @@ class SelectionOverlay { /// A pair of handles. If this is non-null, there are always 2, though the /// second is hidden when the selection is collapsed. - List? _handles; + ({OverlayEntry start, OverlayEntry end})? _handles; /// A copy/paste toolbar. OverlayEntry? _toolbar; @@ -1351,11 +1351,12 @@ class SelectionOverlay { return; } - _handles = [ - OverlayEntry(builder: _buildStartHandle), - OverlayEntry(builder: _buildEndHandle), - ]; - Overlay.of(context, rootOverlay: true, debugRequiredFor: debugRequiredFor).insertAll(_handles!); + _handles = ( + start: OverlayEntry(builder: _buildStartHandle), + end: OverlayEntry(builder: _buildEndHandle), + ); + Overlay.of(context, rootOverlay: true, debugRequiredFor: debugRequiredFor) + .insertAll([_handles!.start, _handles!.end]); } /// {@template flutter.widgets.SelectionOverlay.hideHandles} @@ -1363,10 +1364,10 @@ class SelectionOverlay { /// {@endtemplate} void hideHandles() { if (_handles != null) { - _handles![0].remove(); - _handles![0].dispose(); - _handles![1].remove(); - _handles![1].dispose(); + _handles!.start.remove(); + _handles!.start.dispose(); + _handles!.end.remove(); + _handles!.end.dispose(); _handles = null; } } @@ -1444,8 +1445,8 @@ class SelectionOverlay { SchedulerBinding.instance.addPostFrameCallback((Duration duration) { _buildScheduled = false; if (_handles != null) { - _handles![0].markNeedsBuild(); - _handles![1].markNeedsBuild(); + _handles!.start.markNeedsBuild(); + _handles!.end.markNeedsBuild(); } _toolbar?.markNeedsBuild(); if (_contextMenuController.isShown) { @@ -1456,8 +1457,8 @@ class SelectionOverlay { }); } else { if (_handles != null) { - _handles![0].markNeedsBuild(); - _handles![1].markNeedsBuild(); + _handles!.start.markNeedsBuild(); + _handles!.end.markNeedsBuild(); } _toolbar?.markNeedsBuild(); if (_contextMenuController.isShown) { @@ -1474,10 +1475,10 @@ class SelectionOverlay { void hide() { _magnifierController.hide(); if (_handles != null) { - _handles![0].remove(); - _handles![0].dispose(); - _handles![1].remove(); - _handles![1].dispose(); + _handles!.start.remove(); + _handles!.start.dispose(); + _handles!.end.remove(); + _handles!.end.dispose(); _handles = null; } if (_toolbar != null || _contextMenuController.isShown || _spellCheckToolbarController.isShown) {