Unverified Commit 5f521eea authored by Devon Carew's avatar Devon Carew Committed by GitHub

add route information to Flutter.Navigation events (#34508)

* add route information to Flutter.Navigation events

* route can be null; re-work how we send route info to accomidate that
parent dfa39f3e
...@@ -94,9 +94,16 @@ void main() { ...@@ -94,9 +94,16 @@ void main() {
final Future<VMExtensionEvent> navigationFuture = navigationEvents.first; final Future<VMExtensionEvent> navigationFuture = navigationEvents.first;
// This tap triggers a navigation event. // This tap triggers a navigation event.
device.tap(100, 200); device.tap(100, 200);
final VMExtensionEvent navigationEvent = await navigationFuture; final VMExtensionEvent navigationEvent = await navigationFuture;
// Validate that there are not any fields. // validate the fields
expect(navigationEvent.data.isEmpty); expect(navigationEvent.data['route'] is Map<dynamic, dynamic>);
final Map<dynamic, dynamic> route = navigationEvent.data['route'];
expect(route['description'] is String);
expect(route['settings'] is Map<dynamic, dynamic>);
final Map<dynamic, dynamic> settings = route['settings'];
expect(settings.containsKey('name'));
expect(settings['isInitialRoute'] is bool);
run.stdin.write('q'); run.stdin.write('q');
final int result = await run.exitCode; final int result = await run.exitCode;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:developer' as developer; import 'dart:developer' as developer;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -15,6 +16,7 @@ import 'focus_manager.dart'; ...@@ -15,6 +16,7 @@ import 'focus_manager.dart';
import 'focus_scope.dart'; import 'focus_scope.dart';
import 'framework.dart'; import 'framework.dart';
import 'overlay.dart'; import 'overlay.dart';
import 'routes.dart';
import 'ticker_provider.dart'; import 'ticker_provider.dart';
// Examples can assume: // Examples can assume:
...@@ -1760,18 +1762,46 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin { ...@@ -1760,18 +1762,46 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
for (NavigatorObserver observer in widget.observers) for (NavigatorObserver observer in widget.observers)
observer.didPush(route, oldRoute); observer.didPush(route, oldRoute);
assert(() { _debugLocked = false; return true; }()); assert(() { _debugLocked = false; return true; }());
_afterNavigation(); _afterNavigation(route);
return route.popped; return route.popped;
} }
void _afterNavigation() { void _afterNavigation<T>(Route<T> route) {
if (!kReleaseMode) { if (!kReleaseMode) {
// This event is used by performance tools that show stats for the // Among other uses, performance tools use this event to ensure that perf
// time interval since the last navigation event occurred ensuring that // stats reflect the time interval since the last navigation event
// stats only reflect the current page. // occurred, ensuring that stats only reflect the current page.
// These tools do not need to know exactly what the new route is so no
// attempt is made to describe the current route as part of the event. Map<String, dynamic> routeJsonable;
developer.postEvent('Flutter.Navigation', <String, dynamic>{}); if (route != null) {
routeJsonable = <String, dynamic>{};
String description;
if (route is TransitionRoute<T>) {
final TransitionRoute<T> transitionRoute = route;
description = transitionRoute.debugLabel;
} else {
description = '$route';
}
routeJsonable['description'] = description;
final RouteSettings settings = route.settings;
final Map<String, dynamic> settingsJsonable = <String, dynamic> {
'name': settings.name,
'isInitialRoute': settings.isInitialRoute,
};
if (settings.arguments != null) {
settingsJsonable['arguments'] = jsonEncode(
settings.arguments,
toEncodable: (Object object) => '$object',
);
}
routeJsonable['settings'] = settingsJsonable;
}
developer.postEvent('Flutter.Navigation', <String, dynamic>{
'route': routeJsonable,
});
} }
_cancelActivePointers(); _cancelActivePointers();
} }
...@@ -1825,7 +1855,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin { ...@@ -1825,7 +1855,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
for (NavigatorObserver observer in widget.observers) for (NavigatorObserver observer in widget.observers)
observer.didReplace(newRoute: newRoute, oldRoute: oldRoute); observer.didReplace(newRoute: newRoute, oldRoute: oldRoute);
assert(() { _debugLocked = false; return true; }()); assert(() { _debugLocked = false; return true; }());
_afterNavigation(); _afterNavigation(newRoute);
return newRoute.popped; return newRoute.popped;
} }
...@@ -1879,7 +1909,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin { ...@@ -1879,7 +1909,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
observer.didRemove(removedRoute, oldRoute); observer.didRemove(removedRoute, oldRoute);
} }
assert(() { _debugLocked = false; return true; }()); assert(() { _debugLocked = false; return true; }());
_afterNavigation(); _afterNavigation(newRoute);
return newRoute.popped; return newRoute.popped;
} }
...@@ -2032,7 +2062,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin { ...@@ -2032,7 +2062,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
assert(!debugPredictedWouldPop); assert(!debugPredictedWouldPop);
} }
assert(() { _debugLocked = false; return true; }()); assert(() { _debugLocked = false; return true; }());
_afterNavigation(); _afterNavigation<dynamic>(route);
return true; return true;
} }
...@@ -2074,7 +2104,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin { ...@@ -2074,7 +2104,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
observer.didRemove(route, previousRoute); observer.didRemove(route, previousRoute);
route.dispose(); route.dispose();
assert(() { _debugLocked = false; return true; }()); assert(() { _debugLocked = false; return true; }());
_afterNavigation(); _afterNavigation<dynamic>(nextRoute);
} }
/// Immediately remove a route from the navigator, and [Route.dispose] it. The /// Immediately remove a route from the navigator, and [Route.dispose] it. The
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment