Skip to content

Commit 72aaca5

Browse files
committed
Don't parse doubles as int
1 parent 0ee2168 commit 72aaca5

2 files changed

Lines changed: 2 additions & 10 deletions

File tree

lib/src/pick_int.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ extension IntPick on RequiredPick {
44
/// Returns the picked [value] as [int]
55
///
66
/// {@template Pick.asInt}
7-
/// Parses the picked value as [int]. Other types are parsable as well
8-
/// - [String] is gets parsed via [int.tryParse]
9-
/// - [double] is gets converted to [int] via [num.toInt()]
7+
/// Parses the picked value as [int]. Also tries to parse [String] as [int]
8+
/// via [int.tryParse]
109
/// {@endtemplate}
1110
int asInt() {
1211
final value = this.value;
1312
if (value is int) {
1413
return value;
1514
}
16-
if (value is num) {
17-
return value.toInt();
18-
}
1915
if (value is String) {
2016
final parsed = int.tryParse(value);
2117
if (parsed != null) {

test/src/pick_int_test.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ void main() {
1111
expect(pick(35).asIntOrThrow(), 35);
1212
});
1313

14-
test('parse double', () {
15-
expect(pick(1.0).asIntOrThrow(), 1);
16-
});
17-
1814
test('parse int String', () {
1915
expect(pick('1').asIntOrThrow(), 1);
2016
expect(pick('123').asIntOrThrow(), 123);

0 commit comments

Comments
 (0)