我正在嘗試將一些假資料附加到 Listview.builder 以進行類別顯示,但我不想從 API 獲取資料,所以我只是在 dart 中創建自己的 json
final category = {
"Table": "Category",
"Result": [
{"Name": "Pants", "id": 1, "image": "cat1.png"},
{"Name": "T Shirts", "id": 2, "image": "cat2.png"},
{"Name": "Watches", "id": 3, "image": "cat3.png"}
]
};
我也創建了兩個類
class CategoryList {
String table;
ResultCategory result;
CategoryList(this.table, this.result);
}
class ResultCategory {
String name;
String id;
String image;
ResultCategory(this.name, this.id, this.image);
}
所以我的問題是如何將此資料附加到 Listview.builder
我所做的是
Future<List<CategoryList>> _getCategory() async {
final category = {
"Table": "Category",
"Result": [
{"Name": "Pants", "id": 1, "image": "cat1.png"},
{"Name": "T Shirts", "id": 2, "image": "cat2.png"},
{"Name": "Watches", "id": 3, "image": "cat3.png"}
]
};
Map<String, dynamic> caregoryRes = json.decode(category);
List<CategoryList> categorys = [];
CategoryList categoryList = CategoryList(category.Table, category["Result"]);
categorys.add(categoryList);
return categorys;
}
uj5u.com熱心網友回復:
要加載和顯示資料,您必須使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/527383.html
標籤:安卓扑api镖
