load static method

Future<RunStateStore> load(
  1. File file
)

Implementation

static Future<RunStateStore> load(File file) async {
  if (!await file.exists()) {
    throw FileSystemException('run state not found', file.path);
  }
  final String content;
  try {
    content = await file.readAsString();
  } on FileSystemException {
    rethrow;
  }
  try {
    final json = jsonDecode(content);
    if (json is! Map) throw const FormatException('root is not an object');
    return RunStateStore._(
      file,
      RunState.fromJson(Map<String, dynamic>.from(json)),
    );
  } on Object catch (error) {
    throw FormatException('invalid run state ${file.path}: $error');
  }
}