Это будет работать отлично, проверьте это:
class Person {
final String name;
final String education;
final String skill;
Person({this.name, this.education, this.skill});
factory Person.fromJson(Map<String, dynamic> json) {
return Person(
name: json['name'],
education: json['education'],
skill: json['skill'],
);
}
}
class Fetch extends StatefulWidget {
@override
_FetchState createState() => _FetchState();
}
class _FetchState extends State<Fetch> {
Future<Person> fetchPerson;
Future<Person> getData() async {
String myUrl = "https://api.jsonbin.io/b/5e1219328d761771cc8b9394";
var response = await http.get(myUrl);
Map<String, dynamic> responseJson = convert.jsonDecode(response.body);
return Person.fromJson(responseJson);
}
@override
void initState() {
fetchPerson = getData();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: new Text('hello'),
backgroundColor: Colors.amber,
),
body: FutureBuilder(
future: fetchPerson,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
'Name is: ${snapshot.data.name}',
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
Text(
'Education is: ${snapshot.data.education}',
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
Text(
'Skill is: ${snapshot.data.skill}',
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
],
),
);
} else if (snapshot.hasError) {
Text(
snapshot.error.toString(),
);
}
return Center(
child: CircularProgressIndicator(),
);
},
),
);
}
}
Вывод: