simple future loader json
Future loadJson()async =>
[
{
"displayName": "mario",
"age": 27,
"peso": 85,
"altezza": 175,
"workout": [
{
"nomeworkout": "Running"
},
{
"nomeworkout": "Brucia Grassi"
}
]
},
{
"displayName": "jessica",
"age": 28,
"peso": 85,
"altezza": 175,
"workout": [
{
"nomeworkout": "Spinning"
},
{
"nomeworkout": "Gambe"
}
]
},
{
"displayName": "Pedro",
"age": 29,
"peso": 85,
"altezza": 175,
"workout": [
{
"nomeworkout": "Potenziamento"
}
]
}
];
simple view
class ContohLoadJson extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: FutureBuilder(
future: loadJson(),
builder: (context, snapshot){
List data = snapshot.data??[];
return data.isEmpty?Center(child: CircularProgressIndicator(),):
ListView(
children: List.generate(data.length, (index) =>
Card(
child: Container(
padding: EdgeInsets.all(8),
child: Column(
children: [
Row(
children: [
Text("Name : "),
Text(data[index]['displayName'])
],
),
Row(
children: [
Text("Age : "),
Text(data[index]['age'].toString())
],
),
Row(
children: [
Text("Peso : "),
Text(data[index]['peso'].toString())
],
),
Row(
children: [
Text("altezza: "),
Text(data[index]['altezza'].toString())
],
),
Column(
children: List.generate(data[index]['workout'].length, (index2) =>
Card(
child: Container(
padding: EdgeInsets.all(8),
child: Column(
children: [
Row(
children: [
Text("nomeworkout : "),
Text(data[index]['workout'][index2]['nomeworkout'])
],
)
],
),
),
)
).toList(),
)
],
),
),
)
).toList(),
);
},
)
);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…