diff --git a/packages/flutter/lib/src/widgets/router.dart b/packages/flutter/lib/src/widgets/router.dart index 63db13e365..f0ea086100 100644 --- a/packages/flutter/lib/src/widgets/router.dart +++ b/packages/flutter/lib/src/widgets/router.dart @@ -1465,7 +1465,11 @@ class PlatformRouteInformationProvider extends RouteInformationProvider with Wid /// provider. PlatformRouteInformationProvider({ required RouteInformation initialRouteInformation, - }) : _value = initialRouteInformation; + }) : _value = initialRouteInformation { + if (kFlutterMemoryAllocationsEnabled) { + maybeDispatchObjectCreation(); + } + } static bool _equals(Uri a, Uri b) { return a.path == b.path diff --git a/packages/flutter/test/material/app_test.dart b/packages/flutter/test/material/app_test.dart index 87e8564da5..88aafa258a 100644 --- a/packages/flutter/test/material/app_test.dart +++ b/packages/flutter/test/material/app_test.dart @@ -1161,6 +1161,7 @@ void main() { routerDelegate: delegate, )); expect(tester.takeException(), isAssertionError); + provider.dispose(); }); testWidgetsWithLeakTracking('MaterialApp.router throw if route configuration is provided along with other delegate', (WidgetTester tester) async { diff --git a/packages/flutter/test/widgets/router_test.dart b/packages/flutter/test/widgets/router_test.dart index a552d67b6c..f4286d4586 100644 --- a/packages/flutter/test/widgets/router_test.dart +++ b/packages/flutter/test/widgets/router_test.dart @@ -1582,6 +1582,21 @@ testWidgets('ChildBackButtonDispatcher take priority recursively', (WidgetTester expect(info2.location, '/abc?def=ghi&def=jkl#mno'); }); }); + + test('$PlatformRouteInformationProvider dispatches object creation in constructor', () { + int eventCount = 0; + void listener(ObjectEvent event) => eventCount++; + MemoryAllocations.instance.addListener(listener); + + final PlatformRouteInformationProvider registry = PlatformRouteInformationProvider( + initialRouteInformation: RouteInformation(uri: Uri.parse('http://google.com')), + ); + + expect(eventCount, 1); + + registry.dispose(); + MemoryAllocations.instance.removeListener(listener); + }); } Widget buildBoilerPlate(Widget child) {