Skip to content

Commit e8df434

Browse files
authored
PlatformRouteInformationProvider should dispatch creation in constructor. (#133492)
1 parent 2540412 commit e8df434

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,11 @@ class PlatformRouteInformationProvider extends RouteInformationProvider with Wid
14651465
/// provider.
14661466
PlatformRouteInformationProvider({
14671467
required RouteInformation initialRouteInformation,
1468-
}) : _value = initialRouteInformation;
1468+
}) : _value = initialRouteInformation {
1469+
if (kFlutterMemoryAllocationsEnabled) {
1470+
maybeDispatchObjectCreation();
1471+
}
1472+
}
14691473

14701474
static bool _equals(Uri a, Uri b) {
14711475
return a.path == b.path

packages/flutter/test/material/app_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ void main() {
11611161
routerDelegate: delegate,
11621162
));
11631163
expect(tester.takeException(), isAssertionError);
1164+
provider.dispose();
11641165
});
11651166

11661167
testWidgetsWithLeakTracking('MaterialApp.router throw if route configuration is provided along with other delegate', (WidgetTester tester) async {

packages/flutter/test/widgets/router_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,21 @@ testWidgets('ChildBackButtonDispatcher take priority recursively', (WidgetTester
15821582
expect(info2.location, '/abc?def=ghi&def=jkl#mno');
15831583
});
15841584
});
1585+
1586+
test('$PlatformRouteInformationProvider dispatches object creation in constructor', () {
1587+
int eventCount = 0;
1588+
void listener(ObjectEvent event) => eventCount++;
1589+
MemoryAllocations.instance.addListener(listener);
1590+
1591+
final PlatformRouteInformationProvider registry = PlatformRouteInformationProvider(
1592+
initialRouteInformation: RouteInformation(uri: Uri.parse('http://google.com')),
1593+
);
1594+
1595+
expect(eventCount, 1);
1596+
1597+
registry.dispose();
1598+
MemoryAllocations.instance.removeListener(listener);
1599+
});
15851600
}
15861601

15871602
Widget buildBoilerPlate(Widget child) {

0 commit comments

Comments
 (0)