我只需要將具有 2 個鍵的物件放入串列中的物件 (Classe()) 內的陣列/串列中。
class Classe {
final int id;
final String title, icon;
final List<Object> content;
final Color color;
Classe({
required this.id,
required this.title,
required this.content,
required this.icon,
required this.color,
});
}
List<Classe> classes_ = [
Classe(
id: 0,
title: "Title 1",
content: [
{"type": "text", "src": "Description text 1"},
{"type": "file", "src": "assets/img/logo.png"},
],
icon: "assets/img/settings.png",
color: const Color(0xFF000000),
),
Classe(
id: 1,
title: "Title 2",
content: [
{"type": "text", "src": "Description text 2"},
{"type": "file", "src": "assets/img/img2.png"},
],
icon: "assets/img/img2.png",
color: const Color(0xFFFFFFFF),
),
];
錯誤:lib/pages/classe_view.dart:45:45:錯誤:引數型別“物件”不能分配給引數型別“字串”。
- “物件”來自“飛鏢:核心”。圖片:AssetImage(classe.content[0]), ^
image: AssetImage(classe.content[0].src),
classe 只是“classes_[0]”。
uj5u.com熱心網友回復:
content
應該是 typeList<Map<String, String>>
而不是List<Object>
.
final int id;
final String title, icon;
final List<Map<String, String>> content;
final Color color;
Classe({
required this.id,
required this.title,
required this.content,
required this.icon,
required this.color,
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/504496.html