Not getting all the record of username from json in flutter

Viewed 110

Hello everyone i am parsing a json file in which i am just fetching fields data "username" and "email" but i am not getting all values from the both fields instead i am getting only 5 values from the json file of "username" and "email" fields.

 body: new Center(
       child: new ListView.builder(itemCount: _quakes.length,
           padding: const EdgeInsets.all(16.8),
           itemBuilder: (BuildContext context , int position)
           {
             if(position.isOdd ) return new Divider();
             int index = position ~/ 2;
             return new ListTile(
              title: new Text("${_quakes[index]['username']}"
              , style: new TextStyle(fontSize: 19.2),),
               subtitle: new Text("${_quakes[index]['email']}",
               style: new TextStyle(fontSize: 14.9),),

             );


           }
      )
    )
2 Answers

If you want to have a separator, You can use ListView.separated :

ListView.separated(
  itemCount: _quakes.length,
  itemBuilder: (context, index) {
    return new ListTile(
              title: new Text("${_quakes[index]['username']}"
              , style: new TextStyle(fontSize: 19.2),),
               subtitle: new Text("${_quakes[index]['email']}",
               style: new TextStyle(fontSize: 14.9),),

             );
  },
  separatorBuilder: (context, index) {
    return Divider();
  },
)

in your condition you have to do your itemCount * 2. it will work..

Related