flutter 类型为“List〈Object?>”的值不能赋给类型为“List〈Map〈String,dynamic>>”的变量

2ul0zpep  于 2022-12-14  发布在  Flutter
关注(0)|答案(1)|浏览(187)

它说“类型'List〈Object?〉'的值不能赋给类型'List〈Map〈String,dynamic〉〉'的变量。尝试更改变量的类型,或者将右边的类型强制转换为'List〈Map〈String,dynamic〉〉'”我如何解决它

Future markSetss() async {
    
QuerySnapshot querySnapshot = await FirebaseFirestore.instance
    .collection('stations')
    .where('norequest', isGreaterThanOrEqualTo: 5)
    .get();

List<Map<String, dynamic>> results =
    querySnapshot.docs.map((doc) => doc.data()).toList();

}

cbjzeqam

cbjzeqam1#

您的代码是正确的,它只需要在data()上进行如下类型转换:

List<Map<String, dynamic>> results =
querySnapshot.docs.map((doc) => doc.data() as Map<String, dynamic>).toList();

相关问题