我编写了一个类,用于在我的身体内容中显示一个人的名字列表,但它根本不显示任何内容。
我的问题是,如何使其能够生动地显示从api加载的人员?
这是我关于以下课程的代码:
import 'package:condos/api/http_client.dart';
import 'package:condos/api/query_string.dart';
import 'package:condos/api/response.dart';
import 'package:condos/person.dart';
import 'package:flutter/material.dart';
class About extends StatelessWidget {
HttpClient client = new HttpClient('http://www.mocky.io/v2/');
String title = 'About';
final TextEditingController eCtrl = new TextEditingController();
@override
Widget build(BuildContext context) {
List<Person> persons = new List();
Params params = new Params();
params.add('page', '1');
client
.getPersons('5c096d492f00007d41637e36', params)
.then((Response<List<Person>> response) {
persons = response.content;
print(persons[0].name);
});
return new Scaffold(
appBar: new AppBar(
title: new Text("Dynamic Demo"),
),
body: new Column(
children: <Widget>[
new TextField(
controller: eCtrl,
onSubmitted: (text) {
print(text);
Person person =
new Person.fromAny({"id": "1", "name": 'juan meme'});
print(person.name);
persons.add(person);
eCtrl.clear();
},
),
new Expanded(
child: new ListView.builder(
itemCount: persons.length,
itemBuilder: (BuildContext ctxt, int Index) {
return new Text(persons[Index].name);
}))
],
));
}
}
很抱歉这个问题,但是我对这个框架不熟悉。