我有一个StreamBuilder
每秒给我一个 JSON。我有一个名为“fichajes”的类,它们的属性是:id, worker_id, date, hour, type_checking_id
.
JSON是:
{
"fichajes": [
{
"id": 310,
"worker_id": 1,
"date": "30/09/2019",
"hour": "11:07:04",
"type_checking_id": 2,
"zone_checking_id": null
}
]
}
我想获得一个 json 对象,以便稍后在表格中使用它。
StreamBuilder(
initialData: Center(
child: new CircularProgressIndicator(),
),
stream: _someData(),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.connectionState != ConnectionState.done ||
snapshot.hasError) {
return ListView.builder(
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
final Fichajes fichaje = snapshot.data;
return ListTile(
title: Text("titulo" + fichaje.fichajes[index].id.toString()),
subtitle: Text("subtitulo"),
);
},
);
} else {
return Center(child: LinearProgressIndicator());
}
},
);
Stream<Widget> _someData() async* {
yield* Stream.periodic(
Duration(seconds: 1),
(int a) {
//save into a general variable "allInfo" response from json
loadUser();
print("_someData");
return getInfo();
},
);
}
getInfo() {
return new Container(
child: new Text(allInfo.toString()),
);
}