Skip to content

Commit

Permalink
Remove one-off dynamic invocations (flutter#7102)
Browse files Browse the repository at this point in the history
* Remove one-off dynamic invocations

* feedback
  • Loading branch information
srawlins authored Jan 24, 2024
1 parent f819acc commit b6ef2d9
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ class TestFlutterApp extends IntegrationTestApp {
Map<String, Object?>? _parseFlutterResponse(String line) {
if (line.startsWith('[') && line.endsWith(']')) {
try {
final Map<String, Object?>? resp = json.decode(line)[0];
return resp;
return (json.decode(line) as List)[0];
} catch (e) {
// Not valid JSON, so likely some other output that was surrounded by [brackets]
// Not valid JSON, so likely some other output that was surrounded by
// [brackets].
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@ class _PackageColumn extends TreeColumnData<DominatorTreeNode> {

extension CallGraphNodeDisplay on CallGraphNode {
String get display {
final displayText =
data is ProgramInfoNode ? data.qualifiedName : data.toString();
final displayText = data is ProgramInfoNode
? (data as ProgramInfoNode).qualifiedName
: data.toString();
if (displayText == '@shared') {
// Special case '@shared' because this is the name of the call graph root,
// and '@root' has a more intuitive meaning.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MessageColumn extends ColumnData<LogData>

double frameLength = 0.0;
try {
final int micros = jsonDecode(data.details!)['elapsed'];
final int micros = (jsonDecode(data.details!) as Map)['elapsed'];
frameLength = micros * 3.0 / 1000.0;
} catch (e) {
// ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,11 @@ class _MemoryChartPaneState extends State<MemoryChartPane>
}
} else if (event[eventName] == devToolsEvent &&
event.containsKey(customEvent)) {
final custom = event[customEvent] as Map<dynamic, dynamic>;
final data = custom[customEventData];
final custom = event[customEvent] as Map<Object?, Object?>;
final data = custom[customEventData] as Map<Object?, Object?>;
for (var key in data.keys) {
output.write('$key=');
output.writeln(_longValueToShort(data[key]));
output.writeln(_longValueToShort(data[key] as String));
}
} else {
output.writeln('Unknown Event ${event[eventName]}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ class HttpRequestView extends StatelessWidget {
}

final isJson = switch (requestContentType) {
List() => requestContentType.any((e) => e.contains('json')),
List() =>
requestContentType.any((e) => (e as String).contains('json')),
String() => requestContentType.contains('json'),
_ => throw StateError(
"Expected 'content-type' to be a List or String, but got: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ extension CpuProfilerExtension on VmService {
for (int i = 0; i < samples.length; ++i) {
final cpuSample = samples[i];
final rawSample = rawSamples[i];
cpuSample.setCodeStack(rawSample[kCodeStack].cast<int>());
final codeStack = (rawSample[kCodeStack] as List).cast<int>();
cpuSample.setCodeStack(codeStack);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class IsolateStatisticsViewController extends DisposableController
// given tag's scope in the VM. These raw counts are reported here and
// need to be processed.
final tagCounters = isolate.tagCounters;
final names = tagCounters['names'];
final List<int> counters = tagCounters['counters'].cast<int>();
final names = tagCounters['names'] as List;
final counters = (tagCounters['counters'] as List).cast<int>();
final percentages = <String, double>{};
int totalTickCount = 0;
for (int i = 0; i < counters.length; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools_app/lib/src/service/service_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ class ServiceConnectionManager {
await serviceManager.callServiceExtensionOnMainIsolate(
registrations.flutterListViews,
);
final List<Map<String, Object?>> views =
flutterViewListResponse.json!['views'].cast<Map<String, Object?>>();
final views = (flutterViewListResponse.json!['views'] as List)
.cast<Map<String, Object?>>();

// Each isolate should only have one FlutterView.
final flutterView = views.firstWhereOrNull(
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_app/lib/src/shared/server/_dtd_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Future<Uri?> getDtdUri() async {
final uri = Uri(path: DtdApi.apiGetDtdUri);
final resp = await request(uri.toString());
if (resp?.statusOk ?? false) {
final parsedResult = json.decode(resp!.body);
final parsedResult = json.decode(resp!.body) as Map;

final uriString = parsedResult[DtdApi.uriPropertyName];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Future<List<DevToolsExtensionConfig>> refreshAvailableExtensions(
);
final resp = await request(uri.toString());
if (resp?.statusOk ?? false) {
final parsedResult = json.decode(resp!.body);
final parsedResult = json.decode(resp!.body) as Map;
final extensionsAsJson =
(parsedResult[ExtensionsApi.extensionsResultPropertyName]!
as List<Object?>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Future<void> setLastShownReleaseNotesVersion(String version) async {
'$apiSetLastReleaseNotesVersion'
'?$lastReleaseNotesVersionPropertyName=$version',
);
if (resp == null || !resp.statusOk || !json.decode(resp.body)) {
if (resp == null || !resp.statusOk || !(json.decode(resp.body) as bool)) {
logWarning(resp, apiSetLastReleaseNotesVersion, resp?.body);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Future<void> setSurveyActionTaken() async {
'$apiSetSurveyActionTaken'
'?$surveyActionTakenPropertyName=true',
);
if (resp == null || !resp.statusOk || !json.decode(resp.body)) {
if (resp == null || !resp.statusOk || !(json.decode(resp.body) as bool)) {
logWarning(resp, apiSetSurveyActionTaken, resp?.body);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_app/lib/src/shared/server/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ DevToolsJsonFile _devToolsJsonFileFromResponse(
Response resp,
String filePath,
) {
final data = json.decode(resp.body);
final data = json.decode(resp.body) as Map;
final lastModified = data['lastModifiedTime'];
final lastModifiedTime =
lastModified != null ? DateTime.parse(lastModified) : DateTime.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void setupClipboardCopyListener({
(MethodCall call) {
switch (call.method) {
case 'Clipboard.setData':
clipboardContentsCallback(call.arguments['text']);
clipboardContentsCallback((call.arguments as Map)['text']);
break;
case 'Clipboard.getData':
return Future.value(<String, Object?>{});
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_shared/lib/src/server/file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class LocalFileSystem {
if (!fileName.endsWith('.json')) return null;

final content = file.readAsStringSync();
final json = jsonDecode(content);
final json = jsonDecode(content) as Map;
json['lastModifiedTime'] = file.lastModifiedSync().toString();
return jsonEncode(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ class TestApp {

factory TestApp.fromEnvironment() {
const testArgs = String.fromEnvironment('test_args');
final Map<String, Object> argsMap =
jsonDecode(testArgs).cast<String, Object>();
final argsMap = (jsonDecode(testArgs) as Map).cast<String, Object>();
return TestApp.parse(argsMap);
}

Expand Down

0 comments on commit b6ef2d9

Please sign in to comment.