I need to print startTime form this Map of decodedData. I am new to flutter . I need startTime so that I can show the time slots for availability.
Map decodedData = { "sts" : "SUCCESS", "data" : [{
"slotKey": "1665392445000_|_1665394245000",
"startTime": 1665392445000,
"endTime": 1665394245000,
"isbooked": true,
"bookedBy": "qxWESdGsHvhywe3S7FxDeO2"
},
{
"slotKey": "1665414045000_|_1665415845000",
"startTime": 1665414045000,
"endTime": 1665415845000,
"isbooked": false
},
]};
CodePudding user response:
Try this:
for(var item in decodedData["data"]){
print("startTime = ${item["startTime"]}");
}
CodePudding user response:
You must try this :
decodedData["data"]).values.forEach((v) => print("startTime =
${v["startTime"]}"));
CodePudding user response:
You can use decodedData[0]['startTime'] and so on, you can also use for loop.
and use
DateTime.fromMillisecondsSinceEpoch(decodedData[0]['startTime'],isUtc: true).toString() to print it or format it as per your need.
CodePudding user response:
List<String> arrayStartTime = (decodedData["data"] as List<Map<String,dynamic>>).map((e) => "${e['startTime']}").toList();
result:
[1665392445000, 1665414045000]
You can set array int or String type as per your requirement
CodePudding user response:
Try this:
Map decodedData = { "sts" : "SUCCESS", "data" : [{
"slotKey": "1665392445000_|_1665394245000",
"startTime": 1665392445000,
"endTime": 1665394245000,
"isbooked": true,
"bookedBy": "qxWESdGsHvhywe3S7FxDeO2"
},
{
"slotKey": "1665414045000_|_1665415845000",
"startTime": 1665414045000,
"endTime": 1665415845000,
"isbooked": false
},
]};
void main(){
for(var item in decodedData["data"]){
print("startTime = ${item["startTime"]}");
}
}