Skip to content

Commit

Permalink
Reduce use of dynamic by avoiding Map.fromIterable, List.from, Map.fr…
Browse files Browse the repository at this point in the history
…om (#6931)
  • Loading branch information
srawlins authored Dec 11, 2023
1 parent 8e97ee5 commit af32dfb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,33 +365,28 @@ class FlexLayoutProperties extends LayoutProperties {

static FlexLayoutProperties _buildNode(RemoteDiagnosticsNode node) {
final Map<String, Object?> renderObjectJson = node.renderObject!.json;
final properties = renderObjectJson['properties'] as List<Object?>;
final properties = (renderObjectJson['properties'] as List<Object?>)
.cast<Map<String, Object?>>();

// ignore: prefer_for_elements_to_map_fromiterable, requires refactoring
final data = Map<String, Object?>.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']),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ void main() {
'to json defaults packageUri to resolvedUrl',
() {
const id = '140357727781376-12';
final profileData = Map<String, dynamic>.from(goldenCpuProfileDataJson);
profileData['stackFrames'] = Map<String, Map<String, String?>>.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']);
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,9 @@ void main() {
expect(offlineData.selectedFrameId, equals(1));
expect(offlineData.selectedEvent, isA<OfflineTimelineEvent>());

final expectedFirstTraceJson =
Map<String, dynamic>.from(vsyncEvent.beginTraceEventJson);
expectedFirstTraceJson[TraceEvent.argsKey]
.addAll({TraceEvent.typeKey: TimelineEventType.ui});
final expectedFirstTraceJson = Map.of(vsyncEvent.beginTraceEventJson);
(expectedFirstTraceJson[TraceEvent.argsKey] as Map)
.addAll(<String, dynamic>{TraceEvent.typeKey: TimelineEventType.ui});
expectedFirstTraceJson.addAll(
{TraceEvent.durationKey: vsyncEvent.time.duration.inMicroseconds},
);
Expand Down

0 comments on commit af32dfb

Please sign in to comment.