toTimelineArguments method Null safety

Map<String, String>? toTimelineArguments()

Converts the properties (getProperties) of this node to a form useful for Timeline event arguments (as in Timeline.startSync).

Children (getChildren) are omitted.

This method is only valid in debug builds. In profile builds, this method throws an exception. In release builds it returns null.

See also:

  • toJsonMap, which converts this node to a structured form intended for data exchange (e.g. with an IDE).

Implementation

Map<String, String>? toTimelineArguments() {
  if (!kReleaseMode) {
    // We don't throw in release builds, to avoid hurting users. We also don't do anything useful.
    if (kProfileMode) {
      throw FlutterError(
        // Parts of this string are searched for verbatim by a test in dev/bots/test.dart.
        '$DiagnosticsNode.toTimelineArguments used in non-debug build.\n'
        'The $DiagnosticsNode.toTimelineArguments API is expensive and causes timeline traces '
        'to be non-representative. As such, it should not be used in profile builds. However, '
        'this application is compiled in profile mode and yet still invoked the method.'
      );
    }
    final Map<String, String> result = <String, String>{};
    for (final DiagnosticsNode property in getProperties()) {
      if (property.name != null) {
        result[property.name!] = property.toDescription(parentConfiguration: singleLineTextConfiguration);
      }
    }
    return result;
  }
  return null;
}