Unverified Commit f878bda1 authored by Casey Hillers's avatar Casey Hillers Committed by GitHub

Revert "Change ClipboardStatusNofifier parameter in buildToolbar to V… (#109388)

parent fbca1927
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart' show ValueListenable, clampDouble; import 'package:flutter/foundation.dart' show clampDouble;
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -51,7 +51,7 @@ class CupertinoDesktopTextSelectionControls extends TextSelectionControls { ...@@ -51,7 +51,7 @@ class CupertinoDesktopTextSelectionControls extends TextSelectionControls {
Offset selectionMidpoint, Offset selectionMidpoint,
List<TextSelectionPoint> endpoints, List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate, TextSelectionDelegate delegate,
ValueListenable<ClipboardStatus>? clipboardStatus, ClipboardStatusNotifier? clipboardStatus,
Offset? lastSecondaryTapDownPosition, Offset? lastSecondaryTapDownPosition,
) { ) {
return _CupertinoDesktopTextSelectionControlsToolbar( return _CupertinoDesktopTextSelectionControlsToolbar(
...@@ -106,7 +106,7 @@ class _CupertinoDesktopTextSelectionControlsToolbar extends StatefulWidget { ...@@ -106,7 +106,7 @@ class _CupertinoDesktopTextSelectionControlsToolbar extends StatefulWidget {
required this.lastSecondaryTapDownPosition, required this.lastSecondaryTapDownPosition,
}); });
final ValueListenable<ClipboardStatus>? clipboardStatus; final ClipboardStatusNotifier? clipboardStatus;
final List<TextSelectionPoint> endpoints; final List<TextSelectionPoint> endpoints;
final Rect globalEditableRegion; final Rect globalEditableRegion;
final VoidCallback? handleCopy; final VoidCallback? handleCopy;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter/foundation.dart' show ValueListenable, clampDouble; import 'package:flutter/foundation.dart' show clampDouble;
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'localizations.dart'; import 'localizations.dart';
...@@ -36,7 +36,7 @@ class _CupertinoTextSelectionControlsToolbar extends StatefulWidget { ...@@ -36,7 +36,7 @@ class _CupertinoTextSelectionControlsToolbar extends StatefulWidget {
required this.textLineHeight, required this.textLineHeight,
}); });
final ValueListenable<ClipboardStatus>? clipboardStatus; final ClipboardStatusNotifier? clipboardStatus;
final List<TextSelectionPoint> endpoints; final List<TextSelectionPoint> endpoints;
final Rect globalEditableRegion; final Rect globalEditableRegion;
final VoidCallback? handleCopy; final VoidCallback? handleCopy;
...@@ -213,7 +213,7 @@ class CupertinoTextSelectionControls extends TextSelectionControls { ...@@ -213,7 +213,7 @@ class CupertinoTextSelectionControls extends TextSelectionControls {
Offset selectionMidpoint, Offset selectionMidpoint,
List<TextSelectionPoint> endpoints, List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate, TextSelectionDelegate delegate,
ValueListenable<ClipboardStatus>? clipboardStatus, ClipboardStatusNotifier? clipboardStatus,
Offset? lastSecondaryTapDownPosition, Offset? lastSecondaryTapDownPosition,
) { ) {
return _CupertinoTextSelectionControlsToolbar( return _CupertinoTextSelectionControlsToolbar(
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart' show ValueListenable, clampDouble; import 'package:flutter/foundation.dart' show clampDouble;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -38,7 +38,7 @@ class DesktopTextSelectionControls extends TextSelectionControls { ...@@ -38,7 +38,7 @@ class DesktopTextSelectionControls extends TextSelectionControls {
Offset selectionMidpoint, Offset selectionMidpoint,
List<TextSelectionPoint> endpoints, List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate, TextSelectionDelegate delegate,
ValueListenable<ClipboardStatus>? clipboardStatus, ClipboardStatusNotifier? clipboardStatus,
Offset? lastSecondaryTapDownPosition, Offset? lastSecondaryTapDownPosition,
) { ) {
return _DesktopTextSelectionControlsToolbar( return _DesktopTextSelectionControlsToolbar(
...@@ -103,7 +103,7 @@ class _DesktopTextSelectionControlsToolbar extends StatefulWidget { ...@@ -103,7 +103,7 @@ class _DesktopTextSelectionControlsToolbar extends StatefulWidget {
required this.lastSecondaryTapDownPosition, required this.lastSecondaryTapDownPosition,
}); });
final ValueListenable<ClipboardStatus>? clipboardStatus; final ClipboardStatusNotifier? clipboardStatus;
final List<TextSelectionPoint> endpoints; final List<TextSelectionPoint> endpoints;
final Rect globalEditableRegion; final Rect globalEditableRegion;
final VoidCallback? handleCopy; final VoidCallback? handleCopy;
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'debug.dart'; import 'debug.dart';
...@@ -38,7 +37,7 @@ class MaterialTextSelectionControls extends TextSelectionControls { ...@@ -38,7 +37,7 @@ class MaterialTextSelectionControls extends TextSelectionControls {
Offset selectionMidpoint, Offset selectionMidpoint,
List<TextSelectionPoint> endpoints, List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate, TextSelectionDelegate delegate,
ValueListenable<ClipboardStatus>? clipboardStatus, ClipboardStatusNotifier? clipboardStatus,
Offset? lastSecondaryTapDownPosition, Offset? lastSecondaryTapDownPosition,
) { ) {
return _TextSelectionControlsToolbar( return _TextSelectionControlsToolbar(
...@@ -145,7 +144,7 @@ class _TextSelectionControlsToolbar extends StatefulWidget { ...@@ -145,7 +144,7 @@ class _TextSelectionControlsToolbar extends StatefulWidget {
required this.textLineHeight, required this.textLineHeight,
}); });
final ValueListenable<ClipboardStatus>? clipboardStatus; final ClipboardStatusNotifier? clipboardStatus;
final TextSelectionDelegate delegate; final TextSelectionDelegate delegate;
final List<TextSelectionPoint> endpoints; final List<TextSelectionPoint> endpoints;
final Rect globalEditableRegion; final Rect globalEditableRegion;
......
...@@ -119,7 +119,9 @@ abstract class TextSelectionControls { ...@@ -119,7 +119,9 @@ abstract class TextSelectionControls {
Offset selectionMidpoint, Offset selectionMidpoint,
List<TextSelectionPoint> endpoints, List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate, TextSelectionDelegate delegate,
ValueListenable<ClipboardStatus>? clipboardStatus, // TODO(chunhtai): Change to ValueListenable<ClipboardStatus>? once
// mirgration is done. https://github.com/flutter/flutter/issues/99360
ClipboardStatusNotifier? clipboardStatus,
Offset? lastSecondaryTapDownPosition, Offset? lastSecondaryTapDownPosition,
); );
...@@ -176,7 +178,9 @@ abstract class TextSelectionControls { ...@@ -176,7 +178,9 @@ abstract class TextSelectionControls {
/// ///
/// This is called by subclasses when their cut affordance is activated by /// This is called by subclasses when their cut affordance is activated by
/// the user. /// the user.
void handleCut(TextSelectionDelegate delegate) { // TODO(chunhtai): remove optional parameter once migration is done.
// https://github.com/flutter/flutter/issues/99360
void handleCut(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) {
delegate.cutSelection(SelectionChangedCause.toolbar); delegate.cutSelection(SelectionChangedCause.toolbar);
} }
...@@ -184,7 +188,9 @@ abstract class TextSelectionControls { ...@@ -184,7 +188,9 @@ abstract class TextSelectionControls {
/// ///
/// This is called by subclasses when their copy affordance is activated by /// This is called by subclasses when their copy affordance is activated by
/// the user. /// the user.
void handleCopy(TextSelectionDelegate delegate) { // TODO(chunhtai): remove optional parameter once migration is done.
// https://github.com/flutter/flutter/issues/99360
void handleCopy(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) {
delegate.copySelection(SelectionChangedCause.toolbar); delegate.copySelection(SelectionChangedCause.toolbar);
} }
...@@ -2472,8 +2478,18 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget ...@@ -2472,8 +2478,18 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
ClipboardStatus value = ClipboardStatus.unknown, ClipboardStatus value = ClipboardStatus.unknown,
}) : super(value); }) : 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. /// Check the [Clipboard] and update [value] if needed.
Future<void> update() async { Future<void> update() async {
if (_disposed) {
return;
}
final bool hasStrings; final bool hasStrings;
try { try {
hasStrings = await Clipboard.hasStrings(); hasStrings = await Clipboard.hasStrings();
...@@ -2486,7 +2502,7 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget ...@@ -2486,7 +2502,7 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
)); ));
// In the case of an error from the Clipboard API, set the value to // In the case of an error from the Clipboard API, set the value to
// unknown so that it will try to update again later. // unknown so that it will try to update again later.
if (value == ClipboardStatus.unknown) { if (_disposed || value == ClipboardStatus.unknown) {
return; return;
} }
value = ClipboardStatus.unknown; value = ClipboardStatus.unknown;
...@@ -2497,7 +2513,7 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget ...@@ -2497,7 +2513,7 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
? ClipboardStatus.pasteable ? ClipboardStatus.pasteable
: ClipboardStatus.notPasteable; : ClipboardStatus.notPasteable;
if (nextStatus == value) { if (_disposed || nextStatus == value) {
return; return;
} }
value = nextStatus; value = nextStatus;
...@@ -2517,7 +2533,7 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget ...@@ -2517,7 +2533,7 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
@override @override
void removeListener(VoidCallback listener) { void removeListener(VoidCallback listener) {
super.removeListener(listener); super.removeListener(listener);
if (!hasListeners) { if (!_disposed && !hasListeners) {
WidgetsBinding.instance.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
} }
} }
...@@ -2538,6 +2554,7 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget ...@@ -2538,6 +2554,7 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
@override @override
void dispose() { void dispose() {
WidgetsBinding.instance.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
_disposed = true;
super.dispose(); super.dispose();
} }
} }
......
...@@ -44,7 +44,7 @@ class MockTextSelectionControls extends TextSelectionControls { ...@@ -44,7 +44,7 @@ class MockTextSelectionControls extends TextSelectionControls {
Offset position, Offset position,
List<TextSelectionPoint> endpoints, List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate, TextSelectionDelegate delegate,
ValueListenable<ClipboardStatus>? clipboardStatus, ClipboardStatusNotifier? clipboardStatus,
Offset? lastSecondaryTapDownPosition, Offset? lastSecondaryTapDownPosition,
) { ) {
throw UnimplementedError(); throw UnimplementedError();
......
...@@ -23,7 +23,7 @@ class _CustomCupertinoTextSelectionControls extends CupertinoTextSelectionContro ...@@ -23,7 +23,7 @@ class _CustomCupertinoTextSelectionControls extends CupertinoTextSelectionContro
Offset selectionMidpoint, Offset selectionMidpoint,
List<TextSelectionPoint> endpoints, List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate, TextSelectionDelegate delegate,
ValueListenable<ClipboardStatus>? clipboardStatus, ClipboardStatusNotifier? clipboardStatus,
Offset? lastSecondaryTapDownPosition, Offset? lastSecondaryTapDownPosition,
) { ) {
final MediaQueryData mediaQuery = MediaQuery.of(context); final MediaQueryData mediaQuery = MediaQuery.of(context);
......
...@@ -21,7 +21,7 @@ class _CustomMaterialTextSelectionControls extends MaterialTextSelectionControls ...@@ -21,7 +21,7 @@ class _CustomMaterialTextSelectionControls extends MaterialTextSelectionControls
Offset selectionMidpoint, Offset selectionMidpoint,
List<TextSelectionPoint> endpoints, List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate, TextSelectionDelegate delegate,
ValueListenable<ClipboardStatus>? clipboardStatus, ClipboardStatusNotifier? clipboardStatus,
Offset? lastSecondaryTapDownPosition, Offset? lastSecondaryTapDownPosition,
) { ) {
final TextSelectionPoint startTextSelectionPoint = endpoints[0]; final TextSelectionPoint startTextSelectionPoint = endpoints[0];
......
...@@ -12734,7 +12734,7 @@ class MockTextSelectionControls extends Fake implements TextSelectionControls { ...@@ -12734,7 +12734,7 @@ class MockTextSelectionControls extends Fake implements TextSelectionControls {
Offset position, Offset position,
List<TextSelectionPoint> endpoints, List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate, TextSelectionDelegate delegate,
ValueListenable<ClipboardStatus>? clipboardStatus, ClipboardStatusNotifier? clipboardStatus,
Offset? lastSecondaryTapDownPosition, Offset? lastSecondaryTapDownPosition,
) { ) {
return const SizedBox(); return const SizedBox();
...@@ -12763,8 +12763,10 @@ class MockTextSelectionControls extends Fake implements TextSelectionControls { ...@@ -12763,8 +12763,10 @@ class MockTextSelectionControls extends Fake implements TextSelectionControls {
int pasteCount = 0; int pasteCount = 0;
int copyCount = 0; int copyCount = 0;
// TODO(chunhtai): remove optional parameter once migration is done.
// https://github.com/flutter/flutter/issues/99360
@override @override
void handleCopy(TextSelectionDelegate delegate) { void handleCopy(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) {
copyCount += 1; copyCount += 1;
} }
...@@ -12773,8 +12775,10 @@ class MockTextSelectionControls extends Fake implements TextSelectionControls { ...@@ -12773,8 +12775,10 @@ class MockTextSelectionControls extends Fake implements TextSelectionControls {
pasteCount += 1; pasteCount += 1;
} }
// TODO(chunhtai): remove optional parameter once migration is done.
// https://github.com/flutter/flutter/issues/99360
@override @override
void handleCut(TextSelectionDelegate delegate) { void handleCut(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) {
cutCount += 1; cutCount += 1;
} }
...@@ -12815,7 +12819,7 @@ class _CustomTextSelectionControls extends TextSelectionControls { ...@@ -12815,7 +12819,7 @@ class _CustomTextSelectionControls extends TextSelectionControls {
Offset position, Offset position,
List<TextSelectionPoint> endpoints, List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate, TextSelectionDelegate delegate,
ValueListenable<ClipboardStatus>? clipboardStatus, ClipboardStatusNotifier? clipboardStatus,
Offset? lastSecondaryTapDownPosition, Offset? lastSecondaryTapDownPosition,
) { ) {
final Offset selectionMidpoint = position; final Offset selectionMidpoint = position;
...@@ -12871,9 +12875,9 @@ class _CustomTextSelectionControls extends TextSelectionControls { ...@@ -12871,9 +12875,9 @@ class _CustomTextSelectionControls extends TextSelectionControls {
} }
@override @override
void handleCut(TextSelectionDelegate delegate) { void handleCut(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) {
onCut?.call(); onCut?.call();
return super.handleCut(delegate); return super.handleCut(delegate, clipboardStatus);
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart' show ValueListenable, defaultTargetPlatform; import 'package:flutter/foundation.dart' show defaultTargetPlatform;
import 'package:flutter/gestures.dart' show PointerDeviceKind, kSecondaryButton; import 'package:flutter/gestures.dart' show PointerDeviceKind, kSecondaryButton;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -1456,7 +1456,7 @@ class TextSelectionControlsSpy extends TextSelectionControls { ...@@ -1456,7 +1456,7 @@ class TextSelectionControlsSpy extends TextSelectionControls {
Offset position, Offset position,
List<TextSelectionPoint> endpoints, List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate, TextSelectionDelegate delegate,
ValueListenable<ClipboardStatus>? clipboardStatus, ClipboardStatusNotifier? clipboardStatus,
Offset? lastSecondaryTapDownPosition, Offset? lastSecondaryTapDownPosition,
) { ) {
return Text('dummy', key: toolBarKey); return Text('dummy', key: toolBarKey);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment