Let’s explain my problem..
suppose have a json object like
from this picture i want to handle offer_price key
enter image description here
{
"product": [
{
"id": 1,
"price": 100.0,
"offer_price": 40
},
{
"id": 2,
"price": 80.0,
"offer_price": 10.50
},
{
"id": 3,
"price": 200.0,
"offer_price": "40.5"
},
{
"id": 4,
"price": 100.0,
"offer_price": null,
}
]
}
2
Answers
In the dart data model for
offer_price
field make its datatype as dynamic via which you’ll be able to have a dynamic data in it as run type. And while consuming this in any place just check the runtimeType of the variable and use it by type casting or just using it with.toString()
.eg class:
For consuming it just try: