Home > front end >  Flutter: How to fetch data coming from API which is not in key-value pair format?
Flutter: How to fetch data coming from API which is not in key-value pair format?

Time:10-20

I am getting data in this format how to fetch it and use in UI? Currently i know to ways of fetching data by using snapshot and another one is by storing whole response object is list of array and then fetching data by its key name but there is no key-value pair format in this.So how to fetch data?

[["2022-10-20","baner","03:15:00","no",3000,"Online",147,338,"Owner","Open","8993333333","12000","Adhiraj Nivas ",22019991811063,"pune","Sumitra","Vaishanvi"],["2022-10-19","baner","03:15:00","no",13000,"Online",161,327,"Owner","Open","7652222222","30000","Yashoda Recidency",22100199963254,"pune","sonali Jadhav","Satish"]]

CodePudding user response:

The data is actually a list of lists. To reference a specific element in this data, you need to use two indexes. Please see example code below:

void main() {
  final listsData = [
    ["2022-10-20",
      "baner",
      "03:15:00",
      "no",
      3000,
      "Online",
      147,
      338,
      "Owner",
      "Open",
      "8993333333",
      "12000",
      "Adhiraj Nivas ",
      22019991811063,
      "pune",
      "Sumitra",
      "Vaishanvi"
    ],
    [
      "2022-10-19",
      "baner",
      "03:15:00",
      "no",
      13000,
      "Online",
      161,
      327,
      "Owner",
      "Open",
      "7652222222",
      "30000",
      "Yashoda Recidency",
      22100199963254,
      "pune",
      "sonali Jadhav",
      "Satish"
    ]
  ];
  print(listsData[0][1]); // prints 'baner'
  print(listsData[1][12]); // prints 'Yashoda Recidency'
}

CodePudding user response:

This looks like a List

In dart the equivalent would be a List<dynamic> and you would traverse it with a for loop or specific indices.

CodePudding user response:

It's simply an object. you can do it by using "List" concept with a custom model class.

  • Related