I have data like this
var sendlocal = [
{
"firstName": "tree",
"lastName": "tree",
"relativeEmail": "tree@gmail.com",
"relativeType": 0,
"subid": 1,
"subRelatives": [
{
"firstName": "julia2",
"lastName": "Michle",
"relativeEmail": "test@hotmail.com3",
"relativeType": 2,
"subid": 2,
"subRelatives": [
{
"firstName": "john",
"lastName": "bravo",
"relativeEmail": "johny@gmail.com",
"relativeType": 1,
"subRelatives": [],
"subid": 3,
},
{
"firstName": "simith",
"lastName": "bravo",
"relativeEmail": "johny@gmail.com",
"relativeType": 1,
"subRelatives": [],
"subid": 4,
},
],
},
{
"firstName": "julia3",
"lastName": "Michle",
"relativeEmail": "test3@hotmail.com",
"relativeType": 2,
"subRelatives": [],
"subid": 5,
},
],
},
];
And as per below answer(Thanks) I create a function like this
getIndexFromNestedList(List<dynamic> mapValue) {
if (mapValue != null) {
for (var relation in mapValue) {
print(relation['subid']);
print(relation['relativeEmail']);
if (relation['subRelatives'] != null) {
for (var subRelation in relation['subRelatives']) {
print({relation['subid'], subRelation['subid']});
// graph.addEdge(relation['subid'], subRelation['subid']); //like this
Future.delayed(Duration(milliseconds: 1), () {
getIndexFromNestedList(relation['subRelatives']);
});
}
}
}
}
}
and pass data like this
var check = getIndexFromNestedList(relatives);
And I getting responses like this
flutter: {1, 2}
flutter: {1, 3}
4flutter: {2, null}
What Expected is {2,3} {2,4} and so on if sub relative also have sub relative. But it's showing null don't know why when it's going to sub relatives.