From 98ce4bf7c655d2145d19762384e2d6a21df3acfc Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Wed, 10 Aug 2022 16:26:09 -0700 Subject: [PATCH] =?UTF-8?q?Change=20ClipboardStatusNofifier=20parameter=20?= =?UTF-8?q?in=20buildToolbar=20to=20ValueLise=E2=80=A6=20(#108917)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/cupertino/desktop_text_selection.dart | 6 ++-- .../lib/src/cupertino/text_selection.dart | 6 ++-- .../src/material/desktop_text_selection.dart | 6 ++-- .../lib/src/material/text_selection.dart | 5 ++-- .../lib/src/widgets/text_selection.dart | 29 ++++--------------- .../test/cupertino/text_field_test.dart | 2 +- .../text_selection_toolbar_test.dart | 2 +- .../material/text_selection_toolbar_test.dart | 2 +- .../test/widgets/editable_text_test.dart | 16 ++++------ .../test/widgets/text_selection_test.dart | 4 +-- 10 files changed, 29 insertions(+), 49 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/desktop_text_selection.dart b/packages/flutter/lib/src/cupertino/desktop_text_selection.dart index 037c0b059cb..38b98f98d98 100644 --- a/packages/flutter/lib/src/cupertino/desktop_text_selection.dart +++ b/packages/flutter/lib/src/cupertino/desktop_text_selection.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/foundation.dart' show ValueListenable, clampDouble; import 'package:flutter/gestures.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; @@ -49,7 +49,7 @@ class _CupertinoDesktopTextSelectionControls extends TextSelectionControls { Offset selectionMidpoint, List endpoints, TextSelectionDelegate delegate, - ClipboardStatusNotifier? clipboardStatus, + ValueListenable? clipboardStatus, Offset? lastSecondaryTapDownPosition, ) { return _CupertinoDesktopTextSelectionControlsToolbar( @@ -104,7 +104,7 @@ class _CupertinoDesktopTextSelectionControlsToolbar extends StatefulWidget { required this.lastSecondaryTapDownPosition, }); - final ClipboardStatusNotifier? clipboardStatus; + final ValueListenable? clipboardStatus; final List endpoints; final Rect globalEditableRegion; final VoidCallback? handleCopy; diff --git a/packages/flutter/lib/src/cupertino/text_selection.dart b/packages/flutter/lib/src/cupertino/text_selection.dart index d3be12ca2c6..589cf0d3b4f 100644 --- a/packages/flutter/lib/src/cupertino/text_selection.dart +++ b/packages/flutter/lib/src/cupertino/text_selection.dart @@ -4,7 +4,7 @@ import 'dart:math' as math; -import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/foundation.dart' show ValueListenable, clampDouble; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; @@ -37,7 +37,7 @@ class _CupertinoTextSelectionControlsToolbar extends StatefulWidget { required this.textLineHeight, }); - final ClipboardStatusNotifier? clipboardStatus; + final ValueListenable? clipboardStatus; final List endpoints; final Rect globalEditableRegion; final VoidCallback? handleCopy; @@ -211,7 +211,7 @@ class CupertinoTextSelectionControls extends TextSelectionControls { Offset selectionMidpoint, List endpoints, TextSelectionDelegate delegate, - ClipboardStatusNotifier? clipboardStatus, + ValueListenable? clipboardStatus, Offset? lastSecondaryTapDownPosition, ) { return _CupertinoTextSelectionControlsToolbar( diff --git a/packages/flutter/lib/src/material/desktop_text_selection.dart b/packages/flutter/lib/src/material/desktop_text_selection.dart index 62690434de3..9c55787f9c1 100644 --- a/packages/flutter/lib/src/material/desktop_text_selection.dart +++ b/packages/flutter/lib/src/material/desktop_text_selection.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/foundation.dart' show ValueListenable, clampDouble; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; @@ -35,7 +35,7 @@ class _DesktopTextSelectionControls extends TextSelectionControls { Offset selectionMidpoint, List endpoints, TextSelectionDelegate delegate, - ClipboardStatusNotifier? clipboardStatus, + ValueListenable? clipboardStatus, Offset? lastSecondaryTapDownPosition, ) { return _DesktopTextSelectionControlsToolbar( @@ -100,7 +100,7 @@ class _DesktopTextSelectionControlsToolbar extends StatefulWidget { required this.lastSecondaryTapDownPosition, }); - final ClipboardStatusNotifier? clipboardStatus; + final ValueListenable? clipboardStatus; final List endpoints; final Rect globalEditableRegion; final VoidCallback? handleCopy; diff --git a/packages/flutter/lib/src/material/text_selection.dart b/packages/flutter/lib/src/material/text_selection.dart index e56cad5c582..b090922abb2 100644 --- a/packages/flutter/lib/src/material/text_selection.dart +++ b/packages/flutter/lib/src/material/text_selection.dart @@ -4,6 +4,7 @@ import 'dart:math' as math; +import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; @@ -35,7 +36,7 @@ class MaterialTextSelectionControls extends TextSelectionControls { Offset selectionMidpoint, List endpoints, TextSelectionDelegate delegate, - ClipboardStatusNotifier? clipboardStatus, + ValueListenable? clipboardStatus, Offset? lastSecondaryTapDownPosition, ) { return _TextSelectionControlsToolbar( @@ -142,7 +143,7 @@ class _TextSelectionControlsToolbar extends StatefulWidget { required this.textLineHeight, }); - final ClipboardStatusNotifier? clipboardStatus; + final ValueListenable? clipboardStatus; final TextSelectionDelegate delegate; final List endpoints; final Rect globalEditableRegion; diff --git a/packages/flutter/lib/src/widgets/text_selection.dart b/packages/flutter/lib/src/widgets/text_selection.dart index 102d9405b9d..cbf555723ca 100644 --- a/packages/flutter/lib/src/widgets/text_selection.dart +++ b/packages/flutter/lib/src/widgets/text_selection.dart @@ -113,9 +113,7 @@ abstract class TextSelectionControls { Offset position, List endpoints, TextSelectionDelegate delegate, - // TODO(chunhtai): Change to ValueListenable? once - // mirgration is done. https://github.com/flutter/flutter/issues/99360 - ClipboardStatusNotifier? clipboardStatus, + ValueListenable? clipboardStatus, Offset? lastSecondaryTapDownPosition, ); @@ -172,9 +170,7 @@ abstract class TextSelectionControls { /// /// This is called by subclasses when their cut affordance is activated by /// the user. - // TODO(chunhtai): remove optional parameter once migration is done. - // https://github.com/flutter/flutter/issues/99360 - void handleCut(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) { + void handleCut(TextSelectionDelegate delegate) { delegate.cutSelection(SelectionChangedCause.toolbar); } @@ -182,9 +178,7 @@ abstract class TextSelectionControls { /// /// This is called by subclasses when their copy affordance is activated by /// the user. - // TODO(chunhtai): remove optional parameter once migration is done. - // https://github.com/flutter/flutter/issues/99360 - void handleCopy(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) { + void handleCopy(TextSelectionDelegate delegate) { delegate.copySelection(SelectionChangedCause.toolbar); } @@ -2423,18 +2417,8 @@ class ClipboardStatusNotifier extends ValueNotifier with Widget ClipboardStatus value = ClipboardStatus.unknown, }) : super(value); - bool _disposed = false; - // TODO(chunhtai): remove this getter once migration is done. - // https://github.com/flutter/flutter/issues/99360 - /// True if this instance has been disposed. - bool get disposed => _disposed; - /// Check the [Clipboard] and update [value] if needed. Future update() async { - if (_disposed) { - return; - } - final bool hasStrings; try { hasStrings = await Clipboard.hasStrings(); @@ -2447,7 +2431,7 @@ class ClipboardStatusNotifier extends ValueNotifier with Widget )); // In the case of an error from the Clipboard API, set the value to // unknown so that it will try to update again later. - if (_disposed || value == ClipboardStatus.unknown) { + if (value == ClipboardStatus.unknown) { return; } value = ClipboardStatus.unknown; @@ -2458,7 +2442,7 @@ class ClipboardStatusNotifier extends ValueNotifier with Widget ? ClipboardStatus.pasteable : ClipboardStatus.notPasteable; - if (_disposed || nextStatus == value) { + if (nextStatus == value) { return; } value = nextStatus; @@ -2478,7 +2462,7 @@ class ClipboardStatusNotifier extends ValueNotifier with Widget @override void removeListener(VoidCallback listener) { super.removeListener(listener); - if (!_disposed && !hasListeners) { + if (!hasListeners) { WidgetsBinding.instance.removeObserver(this); } } @@ -2499,7 +2483,6 @@ class ClipboardStatusNotifier extends ValueNotifier with Widget @override void dispose() { WidgetsBinding.instance.removeObserver(this); - _disposed = true; super.dispose(); } } diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index 51a9ccef4ae..8eaba6219d9 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -44,7 +44,7 @@ class MockTextSelectionControls extends TextSelectionControls { Offset position, List endpoints, TextSelectionDelegate delegate, - ClipboardStatusNotifier? clipboardStatus, + ValueListenable? clipboardStatus, Offset? lastSecondaryTapDownPosition, ) { throw UnimplementedError(); diff --git a/packages/flutter/test/cupertino/text_selection_toolbar_test.dart b/packages/flutter/test/cupertino/text_selection_toolbar_test.dart index 82f30e241e9..7403999b96c 100644 --- a/packages/flutter/test/cupertino/text_selection_toolbar_test.dart +++ b/packages/flutter/test/cupertino/text_selection_toolbar_test.dart @@ -24,7 +24,7 @@ class _CustomCupertinoTextSelectionControls extends CupertinoTextSelectionContro Offset selectionMidpoint, List endpoints, TextSelectionDelegate delegate, - ClipboardStatusNotifier? clipboardStatus, + ValueListenable? clipboardStatus, Offset? lastSecondaryTapDownPosition, ) { final MediaQueryData mediaQuery = MediaQuery.of(context); diff --git a/packages/flutter/test/material/text_selection_toolbar_test.dart b/packages/flutter/test/material/text_selection_toolbar_test.dart index 4208c46e2a6..e6d8c1d3c92 100644 --- a/packages/flutter/test/material/text_selection_toolbar_test.dart +++ b/packages/flutter/test/material/text_selection_toolbar_test.dart @@ -22,7 +22,7 @@ class _CustomMaterialTextSelectionControls extends MaterialTextSelectionControls Offset selectionMidpoint, List endpoints, TextSelectionDelegate delegate, - ClipboardStatusNotifier? clipboardStatus, + ValueListenable? clipboardStatus, Offset? lastSecondaryTapDownPosition, ) { final TextSelectionPoint startTextSelectionPoint = endpoints[0]; diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index 584be02aff2..c2ff5de5c8c 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -12734,7 +12734,7 @@ class MockTextSelectionControls extends Fake implements TextSelectionControls { Offset position, List endpoints, TextSelectionDelegate delegate, - ClipboardStatusNotifier? clipboardStatus, + ValueListenable? clipboardStatus, Offset? lastSecondaryTapDownPosition, ) { return const SizedBox(); @@ -12763,10 +12763,8 @@ class MockTextSelectionControls extends Fake implements TextSelectionControls { int pasteCount = 0; int copyCount = 0; - // TODO(chunhtai): remove optional parameter once migration is done. - // https://github.com/flutter/flutter/issues/99360 @override - void handleCopy(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) { + void handleCopy(TextSelectionDelegate delegate) { copyCount += 1; } @@ -12775,10 +12773,8 @@ class MockTextSelectionControls extends Fake implements TextSelectionControls { pasteCount += 1; } - // TODO(chunhtai): remove optional parameter once migration is done. - // https://github.com/flutter/flutter/issues/99360 @override - void handleCut(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) { + void handleCut(TextSelectionDelegate delegate) { cutCount += 1; } @@ -12819,7 +12815,7 @@ class _CustomTextSelectionControls extends TextSelectionControls { Offset position, List endpoints, TextSelectionDelegate delegate, - ClipboardStatusNotifier? clipboardStatus, + ValueListenable? clipboardStatus, Offset? lastSecondaryTapDownPosition, ) { final Offset selectionMidpoint = position; @@ -12875,9 +12871,9 @@ class _CustomTextSelectionControls extends TextSelectionControls { } @override - void handleCut(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) { + void handleCut(TextSelectionDelegate delegate) { onCut?.call(); - return super.handleCut(delegate, clipboardStatus); + return super.handleCut(delegate); } } diff --git a/packages/flutter/test/widgets/text_selection_test.dart b/packages/flutter/test/widgets/text_selection_test.dart index 09980cd9626..eed975c4732 100644 --- a/packages/flutter/test/widgets/text_selection_test.dart +++ b/packages/flutter/test/widgets/text_selection_test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/foundation.dart' show defaultTargetPlatform; +import 'package:flutter/foundation.dart' show ValueListenable, defaultTargetPlatform; import 'package:flutter/gestures.dart' show PointerDeviceKind, kSecondaryButton; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; @@ -1456,7 +1456,7 @@ class TextSelectionControlsSpy extends TextSelectionControls { Offset position, List endpoints, TextSelectionDelegate delegate, - ClipboardStatusNotifier? clipboardStatus, + ValueListenable? clipboardStatus, Offset? lastSecondaryTapDownPosition, ) { return Text('dummy', key: toolBarKey);