Skip to content

Commit f7f89d3

Browse files
committed
add pattern match for company size as well
1 parent 131bf80 commit f7f89d3

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/src/models/account.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class Account {
4141
final String timestamp => DateTime.parse(timestamp),
4242
final int timestamp => DateTime.fromMillisecondsSinceEpoch(timestamp * 1000),
4343
final double timestamp => DateTime.fromMillisecondsSinceEpoch(timestamp.toInt() * 1000),
44-
null => null,
4544
_ => null,
4645
};
4746

lib/src/models/work.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ class Work {
1616

1717
/// The default constructor.
1818
factory Work.fromJson(Map<String, dynamic> json) {
19+
final int? companySize = switch (json['companySize']) {
20+
final int size => size,
21+
final double size => size.toInt(),
22+
_ => null,
23+
};
24+
1925
return Work._(
2026
company: json['company'] as String?,
2127
companyID: json['companyID'] as String?,
22-
// We don't know if company size is an integer or a double here.
23-
// Instead, cast it to num and call `toInt()` on the number instead.
24-
companySize: (json['companySize'] as num?)?.toInt(),
28+
companySize: companySize,
2529
description: json['description'] as String?,
2630
endDate: DateTime.tryParse(json['endDate'] as String? ?? ''),
2731
industry: json['industry'] as String?,

0 commit comments

Comments
 (0)