繁体   English   中英

从 Firebase 读取时,“未为类型‘Object’定义方法‘cast’”

[英]"The method 'cast' isn't defined for the type 'Object'" when reading from Firebase

我在列表视图中创建横幅并从 firebase 数据库中获取数据。

Future<List<String>> getBaners(DatabaseReference bannerRef){
  //The method 'cast' isn't defined for the type 'Object'.
  return bannerRef.once().then((snapshot) => snapshot.snapshot.value!.cast<String>().toList());
}

尝试使用

Future<List<String>> getBaners(DatabaseReference bannerRef)async{ 
  final DataSnapshot res = await bannerRef.get();
  if(res.exists)
    return res.value as List<String>;
  return [];
}
 

如果您能提供有关 bannerRef 指向的数据结构的更多详细信息,我愿意提供更多帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM