Skip to content

[Urgent] fix generate model optional double type#221

Merged
CpdnCristiano merged 1 commit intojonataslaw:masterfrom
knottx:fix-generate-double-type
Sep 8, 2023
Merged

[Urgent] fix generate model optional double type#221
CpdnCristiano merged 1 commit intojonataslaw:masterfrom
knottx:fix-generate-double-type

Conversation

@knottx
Copy link
Contributor

@knottx knottx commented May 5, 2023

The problem is when the json value doesn't have decimal sometimes.
For Example normal value.

{
    "some_value": 123.45
}

And then it works with before.

class Test {
    double? someValue;

    Test.fromJson(Map<String, dynamic> json) {
        someValue = json['some_value'];
    }
}

=======================================================

But sometimes when value doesn't have decimal like this in same attribute.

{
    "some_value": 123
}

It will be seen as an int, my solution should declare as num? first. then use toDouble()

class Test {
    double? someValue;

    Test.fromJson(Map<String, dynamic> json) {
        someValue = (json['some_value'] as num?)?.toDouble();
    }
}

@knottx knottx force-pushed the fix-generate-double-type branch 2 times, most recently from b471cf0 to 30c3813 Compare May 7, 2023 13:04
@knottx knottx changed the title fix generate double type [Urgent] fix generate model optional double type May 7, 2023
@knottx knottx force-pushed the fix-generate-double-type branch from 6e20ba8 to 5ea3fda Compare May 7, 2023 13:37
@knottx knottx force-pushed the fix-generate-double-type branch from 7b16fb2 to 471ec67 Compare August 17, 2023 18:32
@CpdnCristiano
Copy link
Collaborator

Thanks!
LGTM

@CpdnCristiano CpdnCristiano merged commit 89ec8a6 into jonataslaw:master Sep 8, 2023
@knottx knottx deleted the fix-generate-double-type branch March 3, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants