read static method
Reads the index.json in directory.
Point it at an exported page — fw compare --export=<dir> or the
web/ inside --report=<dir>. The comparison cache under
~/.flutterware holds a file of the same name and the same verdict, and
this reads it too; what it cannot do there is open a frame, and frame
says so rather than handing back a path that does not exist.
Throws FormatException when the directory holds no report, or holds one this version cannot read. Both name what was found and what was expected, since the reader is usually looking at build output from elsewhere.
Implementation
static Future<ComparisonReport> read(String directory) async {
var file = File('$directory${Platform.pathSeparator}$comparisonReportFile');
if (!file.existsSync()) {
throw FormatException(
'No $comparisonReportFile in "$directory". '
'Run `fw compare --report=<dir>` first, and read its `web/`.',
);
}
return ComparisonReport(
directory: directory,
index: ComparisonIndex.fromJson(switch (jsonDecode(
await file.readAsString(),
)) {
Map json => json.cast<String, Object?>(),
var other => throw FormatException(
'${file.path} is ${other.runtimeType}, not an object.',
),
}),
);
}