From af32dfbe9d4e3062f034830f5142e1adcaf64f6a Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Mon, 11 Dec 2023 12:45:35 -0800 Subject: [PATCH] Reduce use of dynamic by avoiding Map.fromIterable, List.from, Map.from (#6931) --- .../inspector/inspector_data_models.dart | 41 ++++++++----------- .../cpu_profiler/cpu_profile_model_test.dart | 14 +++---- .../performance/performance_model_test.dart | 7 ++-- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/packages/devtools_app/lib/src/screens/inspector/inspector_data_models.dart b/packages/devtools_app/lib/src/screens/inspector/inspector_data_models.dart index 51cdd3d5ca9..24c27598010 100644 --- a/packages/devtools_app/lib/src/screens/inspector/inspector_data_models.dart +++ b/packages/devtools_app/lib/src/screens/inspector/inspector_data_models.dart @@ -365,33 +365,28 @@ class FlexLayoutProperties extends LayoutProperties { static FlexLayoutProperties _buildNode(RemoteDiagnosticsNode node) { final Map renderObjectJson = node.renderObject!.json; - final properties = renderObjectJson['properties'] as List; + final properties = (renderObjectJson['properties'] as List) + .cast>(); - // ignore: prefer_for_elements_to_map_fromiterable, requires refactoring - final data = Map.fromIterable( - properties, - key: (property) => property['name'], - value: (property) => property['description'], - ); + final data = { + for (final property in properties) + property['name']: property['description'] as String?, + }; return FlexLayoutProperties._fromNode( node, - direction: _directionUtils.enumEntry(data['direction'] as String?) ?? - Axis.vertical, - mainAxisAlignment: _mainAxisAlignmentUtils - .enumEntry(data['mainAxisAlignment'] as String?), - mainAxisSize: - _mainAxisSizeUtils.enumEntry(data['mainAxisSize'] as String?), - crossAxisAlignment: _crossAxisAlignmentUtils - .enumEntry(data['crossAxisAlignment'] as String?), - textDirection: - _textDirectionUtils.enumEntry(data['textDirection'] as String?) ?? - TextDirection.ltr, - verticalDirection: _verticalDirectionUtils - .enumEntry(data['verticalDirection'] as String?) ?? - VerticalDirection.down, - textBaseline: - _textBaselineUtils.enumEntry(data['textBaseline'] as String?), + direction: _directionUtils.enumEntry(data['direction']) ?? Axis.vertical, + mainAxisAlignment: + _mainAxisAlignmentUtils.enumEntry(data['mainAxisAlignment']), + mainAxisSize: _mainAxisSizeUtils.enumEntry(data['mainAxisSize']), + crossAxisAlignment: + _crossAxisAlignmentUtils.enumEntry(data['crossAxisAlignment']), + textDirection: _textDirectionUtils.enumEntry(data['textDirection']) ?? + TextDirection.ltr, + verticalDirection: + _verticalDirectionUtils.enumEntry(data['verticalDirection']) ?? + VerticalDirection.down, + textBaseline: _textBaselineUtils.enumEntry(data['textBaseline']), ); } diff --git a/packages/devtools_app/test/cpu_profiler/cpu_profile_model_test.dart b/packages/devtools_app/test/cpu_profiler/cpu_profile_model_test.dart index 8af25d7b7c1..6dc4c5b8adc 100644 --- a/packages/devtools_app/test/cpu_profiler/cpu_profile_model_test.dart +++ b/packages/devtools_app/test/cpu_profiler/cpu_profile_model_test.dart @@ -135,17 +135,17 @@ void main() { 'to json defaults packageUri to resolvedUrl', () { const id = '140357727781376-12'; - final profileData = Map.from(goldenCpuProfileDataJson); - profileData['stackFrames'] = Map>.from( - {id: goldenCpuProfileStackFrames[id]}, - ); - profileData['stackFrames'][id] - .remove(CpuProfileData.resolvedPackageUriKey); + + final profileData = Map.of(goldenCpuProfileDataJson); + final stackFrame = goldenCpuProfileStackFrames[id] as Map; + final stackFrameData = {id: stackFrame}; + profileData['stackFrames'] = stackFrameData; + stackFrameData[id]!.remove(CpuProfileData.resolvedPackageUriKey); final parsedProfileData = CpuProfileData.parse(profileData); final jsonPackageUri = parsedProfileData.stackFrames[id]!.packageUri; - expect(jsonPackageUri, goldenCpuProfileStackFrames[id]!['resolvedUrl']); + expect(jsonPackageUri, stackFrame['resolvedUrl']); }, ); diff --git a/packages/devtools_app/test/performance/performance_model_test.dart b/packages/devtools_app/test/performance/performance_model_test.dart index e892a35ff99..8fdf5af5268 100644 --- a/packages/devtools_app/test/performance/performance_model_test.dart +++ b/packages/devtools_app/test/performance/performance_model_test.dart @@ -215,10 +215,9 @@ void main() { expect(offlineData.selectedFrameId, equals(1)); expect(offlineData.selectedEvent, isA()); - final expectedFirstTraceJson = - Map.from(vsyncEvent.beginTraceEventJson); - expectedFirstTraceJson[TraceEvent.argsKey] - .addAll({TraceEvent.typeKey: TimelineEventType.ui}); + final expectedFirstTraceJson = Map.of(vsyncEvent.beginTraceEventJson); + (expectedFirstTraceJson[TraceEvent.argsKey] as Map) + .addAll({TraceEvent.typeKey: TimelineEventType.ui}); expectedFirstTraceJson.addAll( {TraceEvent.durationKey: vsyncEvent.time.duration.inMicroseconds}, );