loadFromJson method
Parses jsonText (a *-code-size-analysis_*.json file's contents) and, if it looks valid, replaces the loaded analysis; on failure, leaves any previously loaded analysis in place and sets errorMessage.
Implementation
void loadFromJson(String jsonText, {required String fileName}) {
try {
final decoded = jsonDecode(jsonText);
if (decoded is! Map<String, dynamic>) {
throw const FormatException('Expected a JSON object at the top level.');
}
_setLoaded(
root: SizeAnalysisNode.fromJson(decoded),
fileName: fileName,
platform: decoded['type'] as String?,
isLive: false,
);
} catch (_) {
_errorMessage = '"$fileName" doesn\'t look like a Flutter size analysis file.';
notifyListeners();
}
}