From a9183f696c8e12617d05a26b0b5e80035e515f2a Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Mon, 18 Sep 2023 16:04:06 -0700 Subject: [PATCH] Revert "Resolve breaking change of adding a method to ChangeNotifier." (#134978) Reverts flutter/flutter#134953 Several failures on CI --- .../lib/src/foundation/change_notifier.dart | 14 +++++++------- packages/flutter/lib/src/rendering/paragraph.dart | 2 +- packages/flutter/lib/src/services/restoration.dart | 2 +- .../src/widgets/draggable_scrollable_sheet.dart | 2 +- .../flutter/lib/src/widgets/focus_manager.dart | 4 ++-- .../flutter/lib/src/widgets/focus_traversal.dart | 2 +- packages/flutter/lib/src/widgets/navigator.dart | 2 +- packages/flutter/lib/src/widgets/restoration.dart | 2 +- packages/flutter/lib/src/widgets/router.dart | 2 +- .../flutter/lib/src/widgets/scroll_controller.dart | 2 +- .../flutter/lib/src/widgets/selectable_region.dart | 2 +- packages/flutter/lib/src/widgets/shortcuts.dart | 4 ++-- .../flutter/lib/src/widgets/snapshot_widget.dart | 4 ++++ .../flutter/lib/src/widgets/widget_inspector.dart | 2 +- .../test/foundation/change_notifier_test.dart | 4 ++-- .../test/widgets/automatic_keep_alive_test.dart | 2 +- .../widgets/route_notification_messages_test.dart | 2 +- .../test/widgets/router_restoration_test.dart | 4 ++-- packages/flutter/test/widgets/router_test.dart | 6 +++--- 19 files changed, 34 insertions(+), 30 deletions(-) diff --git a/packages/flutter/lib/src/foundation/change_notifier.dart b/packages/flutter/lib/src/foundation/change_notifier.dart index 7bfc2fb294a26..d8ab7d5720e43 100644 --- a/packages/flutter/lib/src/foundation/change_notifier.dart +++ b/packages/flutter/lib/src/foundation/change_notifier.dart @@ -207,7 +207,7 @@ mixin class ChangeNotifier implements Listenable { @protected bool get hasListeners => _count > 0; - /// Dispatches event of the [object] creation to [MemoryAllocations.instance]. + /// Dispatches event of object creation to [MemoryAllocations.instance]. /// /// If the event was already dispatched or [kFlutterMemoryAllocationsEnabled] /// is false, the method is noop. @@ -227,16 +227,16 @@ mixin class ChangeNotifier implements Listenable { /// Make sure to invoke it with condition `if (kFlutterMemoryAllocationsEnabled) ...` /// so that the method is tree-shaken away when the flag is false. @protected - static void maybeDispatchObjectCreation(ChangeNotifier object) { + void maybeDispatchObjectCreation() { // Tree shaker does not include this method and the class MemoryAllocations // if kFlutterMemoryAllocationsEnabled is false. - if (kFlutterMemoryAllocationsEnabled && !object._creationDispatched) { + if (kFlutterMemoryAllocationsEnabled && !_creationDispatched) { MemoryAllocations.instance.dispatchObjectCreated( library: _flutterFoundationLibrary, className: '$ChangeNotifier', - object: object, + object: this, ); - object._creationDispatched = true; + _creationDispatched = true; } } @@ -271,7 +271,7 @@ mixin class ChangeNotifier implements Listenable { assert(ChangeNotifier.debugAssertNotDisposed(this)); if (kFlutterMemoryAllocationsEnabled) { - maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } if (_count == _listeners.length) { @@ -535,7 +535,7 @@ class ValueNotifier extends ChangeNotifier implements ValueListenable { /// Creates a [ChangeNotifier] that wraps this value. ValueNotifier(this._value) { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index 111ddb3fc4195..79e25371abe7c 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -1321,7 +1321,7 @@ class _SelectableFragment with Selectable, ChangeNotifier implements TextLayoutM required this.range, }) : assert(range.isValid && !range.isCollapsed && range.isNormalized) { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } _selectionGeometry = _getSelectionGeometry(); } diff --git a/packages/flutter/lib/src/services/restoration.dart b/packages/flutter/lib/src/services/restoration.dart index 4bb7811f52764..d3046a0e252cd 100644 --- a/packages/flutter/lib/src/services/restoration.dart +++ b/packages/flutter/lib/src/services/restoration.dart @@ -155,7 +155,7 @@ class RestorationManager extends ChangeNotifier { /// with the engine to get restoration messages (by calling [initChannels]). RestorationManager() { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } initChannels(); } diff --git a/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart b/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart index 276b711db400e..0cb003af71a02 100644 --- a/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart +++ b/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart @@ -1074,7 +1074,7 @@ class _DraggableScrollableActuatorState extends State with ChangeNotifier { /// Creates an instance of [_History]. _History() { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/lib/src/widgets/restoration.dart b/packages/flutter/lib/src/widgets/restoration.dart index f3585417a0e63..367d90e47e80b 100644 --- a/packages/flutter/lib/src/widgets/restoration.dart +++ b/packages/flutter/lib/src/widgets/restoration.dart @@ -457,7 +457,7 @@ abstract class RestorableProperty extends ChangeNotifier { /// Creates a [RestorableProperty]. RestorableProperty(){ if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/lib/src/widgets/router.dart b/packages/flutter/lib/src/widgets/router.dart index c396a949ecf2a..f9ad34b1be7e9 100644 --- a/packages/flutter/lib/src/widgets/router.dart +++ b/packages/flutter/lib/src/widgets/router.dart @@ -1467,7 +1467,7 @@ class PlatformRouteInformationProvider extends RouteInformationProvider with Wid required RouteInformation initialRouteInformation, }) : _value = initialRouteInformation { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/lib/src/widgets/scroll_controller.dart b/packages/flutter/lib/src/widgets/scroll_controller.dart index de88a41acc4a5..1f794b2ee2c9b 100644 --- a/packages/flutter/lib/src/widgets/scroll_controller.dart +++ b/packages/flutter/lib/src/widgets/scroll_controller.dart @@ -65,7 +65,7 @@ class ScrollController extends ChangeNotifier { this.onDetach, }) : _initialScrollOffset = initialScrollOffset { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/lib/src/widgets/selectable_region.dart b/packages/flutter/lib/src/widgets/selectable_region.dart index 371e178e026a3..b0a26c11d04ad 100644 --- a/packages/flutter/lib/src/widgets/selectable_region.dart +++ b/packages/flutter/lib/src/widgets/selectable_region.dart @@ -1580,7 +1580,7 @@ abstract class MultiSelectableSelectionContainerDelegate extends SelectionContai /// Creates an instance of [MultiSelectableSelectionContainerDelegate]. MultiSelectableSelectionContainerDelegate() { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/lib/src/widgets/shortcuts.dart b/packages/flutter/lib/src/widgets/shortcuts.dart index 293d28e979199..c0118e633f608 100644 --- a/packages/flutter/lib/src/widgets/shortcuts.dart +++ b/packages/flutter/lib/src/widgets/shortcuts.dart @@ -749,7 +749,7 @@ class ShortcutManager with Diagnosticable, ChangeNotifier { this.modal = false, }) : _shortcuts = shortcuts { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } @@ -1203,7 +1203,7 @@ class ShortcutRegistry with ChangeNotifier { /// Creates an instance of [ShortcutRegistry]. ShortcutRegistry() { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/lib/src/widgets/snapshot_widget.dart b/packages/flutter/lib/src/widgets/snapshot_widget.dart index 854512f1f4528..7d509ce28ba72 100644 --- a/packages/flutter/lib/src/widgets/snapshot_widget.dart +++ b/packages/flutter/lib/src/widgets/snapshot_widget.dart @@ -482,4 +482,8 @@ class _DefaultSnapshotPainter implements SnapshotPainter { @override bool shouldRepaint(covariant _DefaultSnapshotPainter oldPainter) => false; + + @override + @protected + void maybeDispatchObjectCreation() { } } diff --git a/packages/flutter/lib/src/widgets/widget_inspector.dart b/packages/flutter/lib/src/widgets/widget_inspector.dart index 888a6c817b9fa..66cc2d5abddb0 100644 --- a/packages/flutter/lib/src/widgets/widget_inspector.dart +++ b/packages/flutter/lib/src/widgets/widget_inspector.dart @@ -2898,7 +2898,7 @@ class InspectorSelection with ChangeNotifier { /// Creates an instance of [InspectorSelection]. InspectorSelection() { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/test/foundation/change_notifier_test.dart b/packages/flutter/test/foundation/change_notifier_test.dart index 6bb678a957002..d766c6198dce0 100644 --- a/packages/flutter/test/foundation/change_notifier_test.dart +++ b/packages/flutter/test/foundation/change_notifier_test.dart @@ -29,7 +29,7 @@ class A { class B extends A with ChangeNotifier { B() { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } @@ -43,7 +43,7 @@ class B extends A with ChangeNotifier { class Counter with ChangeNotifier { Counter() { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/test/widgets/automatic_keep_alive_test.dart b/packages/flutter/test/widgets/automatic_keep_alive_test.dart index 089a827d02d5b..60bf9e7cf588d 100644 --- a/packages/flutter/test/widgets/automatic_keep_alive_test.dart +++ b/packages/flutter/test/widgets/automatic_keep_alive_test.dart @@ -638,7 +638,7 @@ class RenderSliverMultiBoxAdaptorAlt extends RenderSliver with class LeakCheckerHandle with ChangeNotifier { LeakCheckerHandle() { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/test/widgets/route_notification_messages_test.dart b/packages/flutter/test/widgets/route_notification_messages_test.dart index 1a3d65ae852cd..1d79ee0ed1c7b 100644 --- a/packages/flutter/test/widgets/route_notification_messages_test.dart +++ b/packages/flutter/test/widgets/route_notification_messages_test.dart @@ -340,7 +340,7 @@ class SimpleRouterDelegate extends RouterDelegate with ChangeN this.reportConfiguration = false, }) { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/test/widgets/router_restoration_test.dart b/packages/flutter/test/widgets/router_restoration_test.dart index 4d429c893d1b0..4892c9c841ffe 100644 --- a/packages/flutter/test/widgets/router_restoration_test.dart +++ b/packages/flutter/test/widgets/router_restoration_test.dart @@ -92,7 +92,7 @@ class _TestRouteInformationParser extends RouteInformationParser { class _TestRouterDelegate extends RouterDelegate with ChangeNotifier { _TestRouterDelegate() { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } @@ -136,7 +136,7 @@ class _TestRouterDelegate extends RouterDelegate with ChangeNotifier { class _TestRouteInformationProvider extends RouteInformationProvider with ChangeNotifier { _TestRouteInformationProvider() { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } diff --git a/packages/flutter/test/widgets/router_test.dart b/packages/flutter/test/widgets/router_test.dart index b6e5ec80cc7d9..fdb3407467c52 100644 --- a/packages/flutter/test/widgets/router_test.dart +++ b/packages/flutter/test/widgets/router_test.dart @@ -1646,7 +1646,7 @@ class SimpleRouterDelegate extends RouterDelegate with ChangeN this.reportConfiguration = false, }) { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } @@ -1734,7 +1734,7 @@ class SimpleRouteInformationProvider extends RouteInformationProvider with Chang this.onRouterReport, }) { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } } @@ -1794,7 +1794,7 @@ class SimpleAsyncRouterDelegate extends RouterDelegate with Ch required this.builder, }) { if (kFlutterMemoryAllocationsEnabled) { - ChangeNotifier.maybeDispatchObjectCreation(this); + maybeDispatchObjectCreation(); } }