Skip to content

Commit

Permalink
Reland Resolve breaking change of adding a method to ChangeNotifier. …
Browse files Browse the repository at this point in the history
…(#134983)
  • Loading branch information
polina-c authored Sep 19, 2023
1 parent a9183f6 commit ab66f55
Show file tree
Hide file tree
Showing 20 changed files with 31 additions and 35 deletions.
14 changes: 7 additions & 7 deletions packages/flutter/lib/src/foundation/change_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ mixin class ChangeNotifier implements Listenable {
@protected
bool get hasListeners => _count > 0;

/// Dispatches event of object creation to [MemoryAllocations.instance].
/// Dispatches event of the [object] creation to [MemoryAllocations.instance].
///
/// If the event was already dispatched or [kFlutterMemoryAllocationsEnabled]
/// is false, the method is noop.
Expand All @@ -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
void maybeDispatchObjectCreation() {
static void maybeDispatchObjectCreation(ChangeNotifier object) {
// Tree shaker does not include this method and the class MemoryAllocations
// if kFlutterMemoryAllocationsEnabled is false.
if (kFlutterMemoryAllocationsEnabled && !_creationDispatched) {
if (kFlutterMemoryAllocationsEnabled && !object._creationDispatched) {
MemoryAllocations.instance.dispatchObjectCreated(
library: _flutterFoundationLibrary,
className: '$ChangeNotifier',
object: this,
object: object,
);
_creationDispatched = true;
object._creationDispatched = true;
}
}

Expand Down Expand Up @@ -271,7 +271,7 @@ mixin class ChangeNotifier implements Listenable {
assert(ChangeNotifier.debugAssertNotDisposed(this));

if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
maybeDispatchObjectCreation(this);
}

if (_count == _listeners.length) {
Expand Down Expand Up @@ -535,7 +535,7 @@ class ValueNotifier<T> extends ChangeNotifier implements ValueListenable<T> {
/// Creates a [ChangeNotifier] that wraps this value.
ValueNotifier(this._value) {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/rendering/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ class _SelectableFragment with Selectable, ChangeNotifier implements TextLayoutM
required this.range,
}) : assert(range.isValid && !range.isCollapsed && range.isNormalized) {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
_selectionGeometry = _getSelectionGeometry();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/services/restoration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class RestorationManager extends ChangeNotifier {
/// with the engine to get restoration messages (by calling [initChannels]).
RestorationManager() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
initChannels();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ class _DraggableScrollableActuatorState extends State<DraggableScrollableActuato
class _ResetNotifier extends ChangeNotifier {
_ResetNotifier() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}
/// Whether someone called [sendReset] or not.
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/focus_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier {
this.debugLabel = debugLabel;

if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down Expand Up @@ -1468,7 +1468,7 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
/// documentation in that method for caveats to watch out for.
FocusManager() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
rootScope._manager = this;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/widgets/focus_traversal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,7 @@ class _FocusTraversalGroupNode extends FocusNode {
required this.policy,
}) {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/widgets/navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3390,7 +3390,7 @@ class _History extends Iterable<_RouteEntry> with ChangeNotifier {
/// Creates an instance of [_History].
_History() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/widgets/restoration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ abstract class RestorableProperty<T> extends ChangeNotifier {
/// Creates a [RestorableProperty].
RestorableProperty(){
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/widgets/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ class PlatformRouteInformationProvider extends RouteInformationProvider with Wid
required RouteInformation initialRouteInformation,
}) : _value = initialRouteInformation {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/widgets/scroll_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ScrollController extends ChangeNotifier {
this.onDetach,
}) : _initialScrollOffset = initialScrollOffset {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/widgets/selectable_region.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ abstract class MultiSelectableSelectionContainerDelegate extends SelectionContai
/// Creates an instance of [MultiSelectableSelectionContainerDelegate].
MultiSelectableSelectionContainerDelegate() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/shortcuts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ class ShortcutManager with Diagnosticable, ChangeNotifier {
this.modal = false,
}) : _shortcuts = shortcuts {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down Expand Up @@ -1203,7 +1203,7 @@ class ShortcutRegistry with ChangeNotifier {
/// Creates an instance of [ShortcutRegistry].
ShortcutRegistry() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
4 changes: 0 additions & 4 deletions packages/flutter/lib/src/widgets/snapshot_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,4 @@ class _DefaultSnapshotPainter implements SnapshotPainter {

@override
bool shouldRepaint(covariant _DefaultSnapshotPainter oldPainter) => false;

@override
@protected
void maybeDispatchObjectCreation() { }
}
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/widgets/widget_inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2898,7 +2898,7 @@ class InspectorSelection with ChangeNotifier {
/// Creates an instance of [InspectorSelection].
InspectorSelection() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/test/foundation/change_notifier_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class A {
class B extends A with ChangeNotifier {
B() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand All @@ -43,7 +43,7 @@ class B extends A with ChangeNotifier {
class Counter with ChangeNotifier {
Counter() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/material/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ class SimpleNavigatorRouterDelegate extends RouterDelegate<RouteInformation> wit
required this.builder,
required this.onPopPage,
}) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ class RenderSliverMultiBoxAdaptorAlt extends RenderSliver with
class LeakCheckerHandle with ChangeNotifier {
LeakCheckerHandle() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class SimpleRouterDelegate extends RouterDelegate<RouteInformation> with ChangeN
this.reportConfiguration = false,
}) {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/test/widgets/router_restoration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class _TestRouteInformationParser extends RouteInformationParser<String> {
class _TestRouterDelegate extends RouterDelegate<String> with ChangeNotifier {
_TestRouterDelegate() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down Expand Up @@ -136,7 +136,7 @@ class _TestRouterDelegate extends RouterDelegate<String> with ChangeNotifier {
class _TestRouteInformationProvider extends RouteInformationProvider with ChangeNotifier {
_TestRouteInformationProvider() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/test/widgets/router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ class SimpleRouterDelegate extends RouterDelegate<RouteInformation> with ChangeN
this.reportConfiguration = false,
}) {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down Expand Up @@ -1734,7 +1734,7 @@ class SimpleRouteInformationProvider extends RouteInformationProvider with Chang
this.onRouterReport,
}) {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down Expand Up @@ -1794,7 +1794,7 @@ class SimpleAsyncRouterDelegate extends RouterDelegate<RouteInformation> with Ch
required this.builder,
}) {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}

Expand Down

0 comments on commit ab66f55

Please sign in to comment.