serialize method Null safety

Map<String, dynamic> serialize()

Serializes this into a JSON-safe object that can be deserialized using Metadata.deserialize.

Implementation

Map<String, dynamic> serialize() {
  // Make this a list to guarantee that the order is preserved.
  var serializedOnPlatform = [];
  onPlatform.forEach((key, value) {
    serializedOnPlatform.add([key.toString(), value.serialize()]);
  });

  return {
    'testOn': testOn == PlatformSelector.all ? null : testOn.toString(),
    'timeout': _serializeTimeout(timeout),
    'skip': _skip,
    'skipReason': skipReason,
    'verboseTrace': _verboseTrace,
    'chainStackTraces': _chainStackTraces,
    'retry': _retry,
    'tags': tags.toList(),
    'onPlatform': serializedOnPlatform,
    'forTag': forTag.map((selector, metadata) =>
        MapEntry(selector.toString(), metadata.serialize())),
    'languageVersionComment': languageVersionComment,
  };
}