in packages/devtools_app/lib/src/memory/memory_screen.dart [111:293]
void didChangeDependencies() {
super.didChangeDependencies();
maybePushDebugModeMemoryMessage(context, MemoryScreen.id);
final newController = Provider.of<MemoryController>(context);
if (newController == controller) return;
controller = newController;
eventChartController = events.EventChartController(controller);
vmChartController = vm.VMChartController(controller);
// Android Chart uses the VM Chart's computed labels.
androidChartController = android.AndroidChartController(
controller,
sharedLabels: vmChartController.labelTimestamps,
);
// Update the chart when the memorySource changes.
addAutoDisposeListener(controller.selectedSnapshotNotifier, () {
setState(() {
// TODO(terry): Create the snapshot data to display by Library,
// by Class or by Objects.
// Create the snapshot data by Library.
controller.createSnapshotByLibrary();
});
});
// Update the chart when the memorySource changes.
addAutoDisposeListener(controller.memorySourceNotifier, () async {
try {
await controller.updatedMemorySource();
} catch (e) {
final errorMessage = '$e';
controller.memorySource = MemoryController.liveFeed;
// Display toast, unable to load the saved memory JSON payload.
final notificationsState = Notifications.of(context);
if (notificationsState != null) {
notificationsState.push(errorMessage);
} else {
// Running in test harness, unexpected error.
throw OfflineFileException(errorMessage);
}
return;
}
controller.refreshAllCharts();
});
addAutoDisposeListener(controller.legendVisibleNotifier, () {
setState(() {
if (controller.isLegendVisible) {
ga.select(
analytics_constants.memory,
analytics_constants.memoryLegend,
);
showLegend(context);
} else {
hideLegend();
}
});
});
addAutoDisposeListener(controller.androidChartVisibleNotifier, () {
setState(() {
if (controller.androidChartVisibleNotifier.value) {
ga.select(
analytics_constants.memory,
analytics_constants.androidChart,
);
}
if (controller.isLegendVisible) {
// Recompute the legend with the new traces now visible.
hideLegend();
showLegend(context);
}
});
});
addAutoDisposeListener(eventChartController.tapLocation, () {
if (eventChartController.tapLocation.value != null) {
if (hoverOverlayEntry != null) {
hideHover();
}
final tapLocation = eventChartController.tapLocation.value;
if (tapLocation?.tapDownDetails != null) {
final tapData = tapLocation;
final index = tapData.index;
final timestamp = tapData.timestamp;
final copied = TapLocation.copy(tapLocation);
vmChartController.tapLocation.value = copied;
androidChartController.tapLocation.value = copied;
final allValues = ChartsValues(controller, index, timestamp);
if (MemoryScreen.isDebuggingEnabled) {
debugLogger('Event Chart TapLocation '
'${allValues.toJson().prettyPrint()}');
}
showHover(context, allValues, tapData.tapDownDetails.globalPosition);
}
}
});
addAutoDisposeListener(vmChartController.tapLocation, () {
if (vmChartController.tapLocation.value != null) {
if (hoverOverlayEntry != null) {
hideHover();
}
final tapLocation = vmChartController.tapLocation.value;
if (tapLocation?.tapDownDetails != null) {
final tapData = tapLocation;
final index = tapData.index;
final timestamp = tapData.timestamp;
final copied = TapLocation.copy(tapLocation);
eventChartController.tapLocation.value = copied;
androidChartController.tapLocation.value = copied;
final allValues = ChartsValues(controller, index, timestamp);
if (MemoryScreen.isDebuggingEnabled) {
debugLogger('VM Chart TapLocation '
'${allValues.toJson().prettyPrint()}');
}
showHover(context, allValues, tapData.tapDownDetails.globalPosition);
}
}
});
addAutoDisposeListener(androidChartController.tapLocation, () {
if (androidChartController.tapLocation.value != null) {
if (hoverOverlayEntry != null) {
hideHover();
}
final tapLocation = androidChartController.tapLocation.value;
if (tapLocation?.tapDownDetails != null) {
final tapData = tapLocation;
final index = tapData.index;
final timestamp = tapData.timestamp;
final copied = TapLocation.copy(tapLocation);
eventChartController.tapLocation.value = copied;
vmChartController.tapLocation.value = copied;
final allValues = ChartsValues(controller, index, timestamp);
if (MemoryScreen.isDebuggingEnabled) {
debugLogger('Android Chart TapLocation '
'${allValues.toJson().prettyPrint()}');
}
showHover(context, allValues, tapData.tapDownDetails.globalPosition);
}
}
});
addAutoDisposeListener(controller.androidCollectionEnabled, () {
isAndroidCollection = controller.androidCollectionEnabled.value;
setState(() {
if (!isAndroidCollection && controller.isAndroidChartVisible) {
// If we're no longer collecting android stats then hide the
// chart and disable the Android Memory button.
controller.toggleAndroidChartVisibility();
}
});
});
addAutoDisposeListener(controller.advancedSettingsEnabled, () {
isAdvancedSettingsEnabled = controller.advancedSettingsEnabled.value;
setState(() {
if (!isAdvancedSettingsEnabled &&
controller.isAdvancedSettingsVisible) {
controller.toggleAdvancedSettingsVisibility();
}
});
});
addAutoDisposeListener(controller.refreshCharts, () {
setState(() {
_refreshCharts();
});
});
_updateListeningState();
}