【发布时间】:2021-09-14 08:30:33
【问题描述】:
@override
Widget build(BuildContext context) {
final id = ModalRoute.of(context)!.settings.arguments;
fetchPhotos() async {
var res = await http.get(Uri.parse("path"));
if (res.statusCode == 200) {
var obj = json.decode(res.body);
return obj;
} else {
return null;
}
}
return Scaffold(
appBar: AppBar(
title: Text(
'Products',
),
),
body: Center(
child: FutureBuilder(
future: fetchPhotos(),
builder: (ctx, snapShot) {
if (snapShot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
} else {
return snapShot.data!["table"] == null ? Center(
child: Text(
"No Data",
),
)
: ListView.builder(
itemCount: snapShot.data!["table"].length,
itemBuilder: (context, index) {
return ListTile(
leading: CircleAvatar(
backgroundColor: Colors.red,
),
title: Text(snapShot.data!["table"][index]["name"]),
subtitle: Text(
"Price : ${snapShot.data!["table"][index]["price"]} ILS"),
trailing: Text(
"Class_id : ${snapShot.data!["table"][index]["class_id"]}"),
);
},
);
}
},
),
),
);
}
在 snapShot.data!["table"][index]["name"] "table" => 没有为类型 'Object' 定义运算符 '[]'。尝试定义运算符 '[] ' / 在它没有给出任何错误并且运行良好之前,看起来这是从更新中发生的
【问题讨论】:
标签: flutter