diff --git a/dev/devicelab/lib/framework/task_result.dart b/dev/devicelab/lib/framework/task_result.dart index 6d58ed03c7..be6e4e433d 100644 --- a/dev/devicelab/lib/framework/task_result.dart +++ b/dev/devicelab/lib/framework/task_result.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:convert'; import 'dart:io'; @@ -25,13 +23,13 @@ class TaskResult { : succeeded = true { const JsonEncoder prettyJson = JsonEncoder.withIndent(' '); if (benchmarkScoreKeys != null) { - for (final String key in benchmarkScoreKeys) { - if (!data.containsKey(key)) { + for (final String key in benchmarkScoreKeys!) { + if (!data!.containsKey(key)) { throw 'Invalid benchmark score key "$key". It does not exist in task ' 'result data ${prettyJson.convert(data)}'; - } else if (data[key] is! num) { + } else if (data![key] is! num) { throw 'Invalid benchmark score for key "$key". It is expected to be a num ' - 'but was ${(data[key] as Object).runtimeType}: ${prettyJson.convert(data[key])}'; + 'but was ${(data![key] as Object).runtimeType}: ${prettyJson.convert(data![key])}'; } } } @@ -53,8 +51,8 @@ class TaskResult { factory TaskResult.fromJson(Map json) { final bool success = json['success'] as bool; if (success) { - final List benchmarkScoreKeys = (json['benchmarkScoreKeys'] as List ?? []).cast(); - final List detailFiles = (json['detailFiles'] as List ?? []).cast(); + final List benchmarkScoreKeys = (json['benchmarkScoreKeys'] as List? ?? []).cast(); + final List detailFiles = (json['detailFiles'] as List? ?? []).cast(); return TaskResult.success(json['data'] as Map, benchmarkScoreKeys: benchmarkScoreKeys, detailFiles: detailFiles, @@ -76,15 +74,15 @@ class TaskResult { final bool succeeded; /// Task-specific JSON data - final Map data; + final Map? data; /// Files containing detail on the run (e.g. timeline trace files) - final List detailFiles; + final List? detailFiles; /// Keys in [data] that store scores that will be submitted to Cocoon. /// /// Each key is also part of a benchmark's name tracked by Cocoon. - final List benchmarkScoreKeys; + final List? benchmarkScoreKeys; /// Whether the task failed. bool get failed => !succeeded;