Skip to content

Commit ab66f55

Browse files
authored
Reland Resolve breaking change of adding a method to ChangeNotifier. (#134983)
1 parent a9183f6 commit ab66f55

20 files changed

+31
-35
lines changed

packages/flutter/lib/src/foundation/change_notifier.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ mixin class ChangeNotifier implements Listenable {
207207
@protected
208208
bool get hasListeners => _count > 0;
209209

210-
/// Dispatches event of object creation to [MemoryAllocations.instance].
210+
/// Dispatches event of the [object] creation to [MemoryAllocations.instance].
211211
///
212212
/// If the event was already dispatched or [kFlutterMemoryAllocationsEnabled]
213213
/// is false, the method is noop.
@@ -227,16 +227,16 @@ mixin class ChangeNotifier implements Listenable {
227227
/// Make sure to invoke it with condition `if (kFlutterMemoryAllocationsEnabled) ...`
228228
/// so that the method is tree-shaken away when the flag is false.
229229
@protected
230-
void maybeDispatchObjectCreation() {
230+
static void maybeDispatchObjectCreation(ChangeNotifier object) {
231231
// Tree shaker does not include this method and the class MemoryAllocations
232232
// if kFlutterMemoryAllocationsEnabled is false.
233-
if (kFlutterMemoryAllocationsEnabled && !_creationDispatched) {
233+
if (kFlutterMemoryAllocationsEnabled && !object._creationDispatched) {
234234
MemoryAllocations.instance.dispatchObjectCreated(
235235
library: _flutterFoundationLibrary,
236236
className: '$ChangeNotifier',
237-
object: this,
237+
object: object,
238238
);
239-
_creationDispatched = true;
239+
object._creationDispatched = true;
240240
}
241241
}
242242

@@ -271,7 +271,7 @@ mixin class ChangeNotifier implements Listenable {
271271
assert(ChangeNotifier.debugAssertNotDisposed(this));
272272

273273
if (kFlutterMemoryAllocationsEnabled) {
274-
maybeDispatchObjectCreation();
274+
maybeDispatchObjectCreation(this);
275275
}
276276

277277
if (_count == _listeners.length) {
@@ -535,7 +535,7 @@ class ValueNotifier<T> extends ChangeNotifier implements ValueListenable<T> {
535535
/// Creates a [ChangeNotifier] that wraps this value.
536536
ValueNotifier(this._value) {
537537
if (kFlutterMemoryAllocationsEnabled) {
538-
maybeDispatchObjectCreation();
538+
ChangeNotifier.maybeDispatchObjectCreation(this);
539539
}
540540
}
541541

packages/flutter/lib/src/rendering/paragraph.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ class _SelectableFragment with Selectable, ChangeNotifier implements TextLayoutM
13211321
required this.range,
13221322
}) : assert(range.isValid && !range.isCollapsed && range.isNormalized) {
13231323
if (kFlutterMemoryAllocationsEnabled) {
1324-
maybeDispatchObjectCreation();
1324+
ChangeNotifier.maybeDispatchObjectCreation(this);
13251325
}
13261326
_selectionGeometry = _getSelectionGeometry();
13271327
}

packages/flutter/lib/src/services/restoration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class RestorationManager extends ChangeNotifier {
155155
/// with the engine to get restoration messages (by calling [initChannels]).
156156
RestorationManager() {
157157
if (kFlutterMemoryAllocationsEnabled) {
158-
maybeDispatchObjectCreation();
158+
ChangeNotifier.maybeDispatchObjectCreation(this);
159159
}
160160
initChannels();
161161
}

packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ class _DraggableScrollableActuatorState extends State<DraggableScrollableActuato
10741074
class _ResetNotifier extends ChangeNotifier {
10751075
_ResetNotifier() {
10761076
if (kFlutterMemoryAllocationsEnabled) {
1077-
maybeDispatchObjectCreation();
1077+
ChangeNotifier.maybeDispatchObjectCreation(this);
10781078
}
10791079
}
10801080
/// Whether someone called [sendReset] or not.

packages/flutter/lib/src/widgets/focus_manager.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier {
439439
this.debugLabel = debugLabel;
440440

441441
if (kFlutterMemoryAllocationsEnabled) {
442-
maybeDispatchObjectCreation();
442+
ChangeNotifier.maybeDispatchObjectCreation(this);
443443
}
444444
}
445445

@@ -1468,7 +1468,7 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
14681468
/// documentation in that method for caveats to watch out for.
14691469
FocusManager() {
14701470
if (kFlutterMemoryAllocationsEnabled) {
1471-
maybeDispatchObjectCreation();
1471+
ChangeNotifier.maybeDispatchObjectCreation(this);
14721472
}
14731473
rootScope._manager = this;
14741474
}

packages/flutter/lib/src/widgets/focus_traversal.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ class _FocusTraversalGroupNode extends FocusNode {
17881788
required this.policy,
17891789
}) {
17901790
if (kFlutterMemoryAllocationsEnabled) {
1791-
maybeDispatchObjectCreation();
1791+
ChangeNotifier.maybeDispatchObjectCreation(this);
17921792
}
17931793
}
17941794

packages/flutter/lib/src/widgets/navigator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3390,7 +3390,7 @@ class _History extends Iterable<_RouteEntry> with ChangeNotifier {
33903390
/// Creates an instance of [_History].
33913391
_History() {
33923392
if (kFlutterMemoryAllocationsEnabled) {
3393-
maybeDispatchObjectCreation();
3393+
ChangeNotifier.maybeDispatchObjectCreation(this);
33943394
}
33953395
}
33963396

packages/flutter/lib/src/widgets/restoration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ abstract class RestorableProperty<T> extends ChangeNotifier {
457457
/// Creates a [RestorableProperty].
458458
RestorableProperty(){
459459
if (kFlutterMemoryAllocationsEnabled) {
460-
maybeDispatchObjectCreation();
460+
ChangeNotifier.maybeDispatchObjectCreation(this);
461461
}
462462
}
463463

packages/flutter/lib/src/widgets/router.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ class PlatformRouteInformationProvider extends RouteInformationProvider with Wid
14671467
required RouteInformation initialRouteInformation,
14681468
}) : _value = initialRouteInformation {
14691469
if (kFlutterMemoryAllocationsEnabled) {
1470-
maybeDispatchObjectCreation();
1470+
ChangeNotifier.maybeDispatchObjectCreation(this);
14711471
}
14721472
}
14731473

packages/flutter/lib/src/widgets/scroll_controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ScrollController extends ChangeNotifier {
6565
this.onDetach,
6666
}) : _initialScrollOffset = initialScrollOffset {
6767
if (kFlutterMemoryAllocationsEnabled) {
68-
maybeDispatchObjectCreation();
68+
ChangeNotifier.maybeDispatchObjectCreation(this);
6969
}
7070
}
7171

packages/flutter/lib/src/widgets/selectable_region.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ abstract class MultiSelectableSelectionContainerDelegate extends SelectionContai
15801580
/// Creates an instance of [MultiSelectableSelectionContainerDelegate].
15811581
MultiSelectableSelectionContainerDelegate() {
15821582
if (kFlutterMemoryAllocationsEnabled) {
1583-
maybeDispatchObjectCreation();
1583+
ChangeNotifier.maybeDispatchObjectCreation(this);
15841584
}
15851585
}
15861586

packages/flutter/lib/src/widgets/shortcuts.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ class ShortcutManager with Diagnosticable, ChangeNotifier {
749749
this.modal = false,
750750
}) : _shortcuts = shortcuts {
751751
if (kFlutterMemoryAllocationsEnabled) {
752-
maybeDispatchObjectCreation();
752+
ChangeNotifier.maybeDispatchObjectCreation(this);
753753
}
754754
}
755755

@@ -1203,7 +1203,7 @@ class ShortcutRegistry with ChangeNotifier {
12031203
/// Creates an instance of [ShortcutRegistry].
12041204
ShortcutRegistry() {
12051205
if (kFlutterMemoryAllocationsEnabled) {
1206-
maybeDispatchObjectCreation();
1206+
ChangeNotifier.maybeDispatchObjectCreation(this);
12071207
}
12081208
}
12091209

packages/flutter/lib/src/widgets/snapshot_widget.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,4 @@ class _DefaultSnapshotPainter implements SnapshotPainter {
482482

483483
@override
484484
bool shouldRepaint(covariant _DefaultSnapshotPainter oldPainter) => false;
485-
486-
@override
487-
@protected
488-
void maybeDispatchObjectCreation() { }
489485
}

packages/flutter/lib/src/widgets/widget_inspector.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,7 @@ class InspectorSelection with ChangeNotifier {
28982898
/// Creates an instance of [InspectorSelection].
28992899
InspectorSelection() {
29002900
if (kFlutterMemoryAllocationsEnabled) {
2901-
maybeDispatchObjectCreation();
2901+
ChangeNotifier.maybeDispatchObjectCreation(this);
29022902
}
29032903
}
29042904

packages/flutter/test/foundation/change_notifier_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class A {
2929
class B extends A with ChangeNotifier {
3030
B() {
3131
if (kFlutterMemoryAllocationsEnabled) {
32-
maybeDispatchObjectCreation();
32+
ChangeNotifier.maybeDispatchObjectCreation(this);
3333
}
3434
}
3535

@@ -43,7 +43,7 @@ class B extends A with ChangeNotifier {
4343
class Counter with ChangeNotifier {
4444
Counter() {
4545
if (kFlutterMemoryAllocationsEnabled) {
46-
maybeDispatchObjectCreation();
46+
ChangeNotifier.maybeDispatchObjectCreation(this);
4747
}
4848
}
4949

packages/flutter/test/material/app_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ class SimpleNavigatorRouterDelegate extends RouterDelegate<RouteInformation> wit
15701570
required this.builder,
15711571
required this.onPopPage,
15721572
}) {
1573-
maybeDispatchObjectCreation();
1573+
ChangeNotifier.maybeDispatchObjectCreation(this);
15741574
}
15751575

15761576
@override

packages/flutter/test/widgets/automatic_keep_alive_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ class RenderSliverMultiBoxAdaptorAlt extends RenderSliver with
638638
class LeakCheckerHandle with ChangeNotifier {
639639
LeakCheckerHandle() {
640640
if (kFlutterMemoryAllocationsEnabled) {
641-
maybeDispatchObjectCreation();
641+
ChangeNotifier.maybeDispatchObjectCreation(this);
642642
}
643643
}
644644

packages/flutter/test/widgets/route_notification_messages_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class SimpleRouterDelegate extends RouterDelegate<RouteInformation> with ChangeN
340340
this.reportConfiguration = false,
341341
}) {
342342
if (kFlutterMemoryAllocationsEnabled) {
343-
maybeDispatchObjectCreation();
343+
ChangeNotifier.maybeDispatchObjectCreation(this);
344344
}
345345
}
346346

packages/flutter/test/widgets/router_restoration_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class _TestRouteInformationParser extends RouteInformationParser<String> {
9292
class _TestRouterDelegate extends RouterDelegate<String> with ChangeNotifier {
9393
_TestRouterDelegate() {
9494
if (kFlutterMemoryAllocationsEnabled) {
95-
maybeDispatchObjectCreation();
95+
ChangeNotifier.maybeDispatchObjectCreation(this);
9696
}
9797
}
9898

@@ -136,7 +136,7 @@ class _TestRouterDelegate extends RouterDelegate<String> with ChangeNotifier {
136136
class _TestRouteInformationProvider extends RouteInformationProvider with ChangeNotifier {
137137
_TestRouteInformationProvider() {
138138
if (kFlutterMemoryAllocationsEnabled) {
139-
maybeDispatchObjectCreation();
139+
ChangeNotifier.maybeDispatchObjectCreation(this);
140140
}
141141
}
142142

packages/flutter/test/widgets/router_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ class SimpleRouterDelegate extends RouterDelegate<RouteInformation> with ChangeN
16461646
this.reportConfiguration = false,
16471647
}) {
16481648
if (kFlutterMemoryAllocationsEnabled) {
1649-
maybeDispatchObjectCreation();
1649+
ChangeNotifier.maybeDispatchObjectCreation(this);
16501650
}
16511651
}
16521652

@@ -1734,7 +1734,7 @@ class SimpleRouteInformationProvider extends RouteInformationProvider with Chang
17341734
this.onRouterReport,
17351735
}) {
17361736
if (kFlutterMemoryAllocationsEnabled) {
1737-
maybeDispatchObjectCreation();
1737+
ChangeNotifier.maybeDispatchObjectCreation(this);
17381738
}
17391739
}
17401740

@@ -1794,7 +1794,7 @@ class SimpleAsyncRouterDelegate extends RouterDelegate<RouteInformation> with Ch
17941794
required this.builder,
17951795
}) {
17961796
if (kFlutterMemoryAllocationsEnabled) {
1797-
maybeDispatchObjectCreation();
1797+
ChangeNotifier.maybeDispatchObjectCreation(this);
17981798
}
17991799
}
18001800

0 commit comments

Comments
 (0)