[英]Flutter conditional list
当我从下拉列表中选择时,我想显示数据列表,但仍然出现错误 LateInitializationError: Field 'listTanaman' has not been initialized。 我只是初始化变量而不给变量赋值。
我像这样初始化变量
List<Komoditas>? listTanaman;
并在此下拉列表中分配
DropdownButton(
value: dropdownValue,
items: snapshot.data!.docs
.map((DocumentSnapshot doc) {
return DropdownMenuItem(
value: doc.id,
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(5)),
height: 100,
padding: const EdgeInsets.all(10),
child: Text(doc.get('nama')),
),
);
}).toList(),
onChanged: (newValue) {
setState(() {
dropdownValue = newValue.toString();
kategori = snapshot.data!.docs
.where((newValue) => true)
.first
.get('nama');
});
db
.collection('kategori')
.doc(dropdownValue)
.collection(kategori!)
.snapshots()
.map((event) => listTanaman);
}),
有谁知道我的错在哪里?
如果您需要检查某些内容是否已初始化,则应该使用可为空的变量而不是Late
改变这个:
Late String Listkategori;//or
Late List Listkategori;
至
String? Listkategori;
List<urtype> Listkategori = [];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.