DevToolsExtensionConfig.parse constructor
Implementation
factory DevToolsExtensionConfig.parse(Map<String, Object?> json) {
// Defaults to the code point for [Icons.extensions_outlined] if null.
late int codePoint;
final codePointFromJson = json[materialIconCodePointKey];
const defaultCodePoint = 0xf03f;
if (codePointFromJson is String?) {
codePoint =
int.tryParse(codePointFromJson ?? '0xf03f') ?? defaultCodePoint;
} else {
codePoint = codePointFromJson as int? ?? defaultCodePoint;
}
if (json
case {
nameKey: final String name,
pathKey: final String path,
issueTrackerKey: final String issueTracker,
versionKey: final String version,
}) {
return DevToolsExtensionConfig._(
name: name,
path: path,
issueTrackerLink: issueTracker,
version: version,
materialIconCodePoint: codePoint,
);
} else {
const requiredKeys = {nameKey, pathKey, issueTrackerKey, versionKey};
final diff = requiredKeys.difference(json.keys.toSet());
if (diff.isEmpty) {
// All the required keys are present, but the value types did not match.
final sb = StringBuffer();
for (final entry in json.entries) {
sb.writeln(
' ${entry.key}: ${entry.value} (${entry.value.runtimeType})',
);
}
throw StateError(
'Unexpected value types in the extension config.yaml. Expected all '
'values to be of type String, but one or more had a different type:\n'
'${sb.toString()}',
);
} else {
throw StateError(
'Missing required fields ${diff.toString()} in the extension '
'config.yaml.',
);
}
}
}