gpt4 book ai didi

json - 使用 ListView 在行中显示 json 数据

转载 作者:IT王子 更新时间:2023-10-29 07:02:48 25 4
gpt4 key购买 nike

我想把activity中的数据显示到ListView中下面是图像 enter image description here

如果这是我的代码

    FutureBuilder(
future: UserController.getActivity(_selectedUser),
builder: (context, snapshot) {
if(snapshot.hasData){
return Column(
children: <Widget>[
Expanded

(
child: ListView.separated(
itemCount: snapshot.data.length,
itemBuilder: (context, position){
var item = snapshot.data.elementAt(position);
return Text(item[0]["activity "]);
}
),
)
],
);
}

return Center(
child: CircularProgressIndicator(),
);
},
),

这里是 api.dart 的代码

   static getCompany() async {
return await Http.get("user/getCompany");
}

这是数据库的 Controller 代码

public function GetCompany() {
$sql = "SELECT
clients.companies.name
FROM
clients.companies";
$parameter = [];

return $this->queryArray($sql, $parameter);
}

和 library.php 中的 queryArray

protected function queryArray($sql, $parameter){
try {
$stmt = $this->query($sql, $parameter);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}catch(Exception $e){
return array();
}
}

最佳答案

这是代码,我如何从 firebase 获取数据

Future<void> _getCarList() async {
_list.clear();

setState(() {
isApiInExecution = true;
});

await _driveListRef.once().then((DataSnapshot snapshot) {
setState(() {
isApiInExecution = false;
});

if (snapshot == null || snapshot.value == null) {
return;
}
print(' 11 Connected to second database and read ${snapshot.value}');
// HashMap<String, String> _values = snapshot.value;
snapshot.value.forEach((key, _vehicleModel) {
VehicleModel vehicleModel = VehicleModel(
rego: (_vehicleModel['rego'] != null ? _vehicleModel['rego'] : ""),
state:
(_vehicleModel['state'] != null ? _vehicleModel['state'] : ""),
vin: (_vehicleModel['vin'] != null ? _vehicleModel['vin'] : ""),
year: (_vehicleModel['year'] != null ? _vehicleModel['year'] : ""),
make: (_vehicleModel['make'] != null ? _vehicleModel['make'] : ""),
model:
(_vehicleModel['model'] != null ? _vehicleModel['model'] : ""),
colour: (_vehicleModel['colour'] != null
? _vehicleModel['colour']
: ""));

_list.add(vehicleModel);
});
}).then((onError) {
if (onError == null) {
return;
}
print('On Error Connected to second database and read $onError');
});
}

希望对你有帮助

关于json - 使用 ListView 在行中显示 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56698086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com