Here is my solution
I have the following json
[
{
"name": "Abhijit Sawant",
"age": "23",
"height":"180",
"gender": "male",
"hair_color": "black"
},
{
"name": "Akku Sawant",
"age": "23",
"height":"150",
"gender": "male",
"hair_color": "brown"
},
{
"name": "Pikki Sawant",
"age": "23",
"height":"120",
"gender": "male",
"hair_color": "grey"
},
{
"name": "Chikki Sawant",
"age": "23",
"height":"100",
"gender": "female",
"hair_color": "white"
}
]
Following is my Flutter Code
class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return HomePageState();
}
}
class HomePageState extends State<HomePage>{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Loading Json"),),
body: Container(
child: Center(
child: FutureBuilder(builder: (context,snapshot){
var myData = json.decode(snapshot.data.toString());
return new ListView.builder(
itemCount: myData == null ? 0: myData.length,
itemBuilder: (BuildContext context,int index){
return Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text("Name: "+myData[index]["name"]),
Text("Age: "+myData[index]["age"]),
Text("Height: "+myData[index]["height"]),
Text("Gender: "+myData[index]["gender"]),
],
),
);
},);
},
future: DefaultAssetBundle.of(context).loadString("person.json"),),
),
),
);
}
}