gpt4 book ai didi

firebase - flutter :[cloud_firestore/unknown] NoSuchMethodError: invalid member on null: 'includeMetadataChanges' (Flutter Web)

转载 作者:行者123 更新时间:2023-12-03 15:21:52 27 4
gpt4 key购买 nike

我正在尝试从 Friebase-firestore 获取数据,然后将其转换为模型,我对另一个项目(网络项目)使用了相同的代码和方法,它工作正常,但对于这个项目它不起作用,我不知道为什么。我升级了 flutter 版本,运行 Flutter doctor ,环境设置没有问题。
这是代码:

class dbService{

static final CollectionReference myCollection =
FirebaseFirestore.instance.collection('myCollection');

static Future<myModel> getMyInfo() async{
myModel sanaa ;
print('this line to print');
final QuerySnapshot myInfo =await myCollection.limit(1).get();
myInfo.docs.forEach((element) {
print(element.data()['name']);
sanaa= new myModel(
name:element.data()['name'].toString(),
title: element.data()["title"].toString(),
img: element.data()['img'].toString(),
);
print('\n print ------ ');
print(element.data()['name']);
print(' that is');
}

);
return sanaa;

}
}
class dbManager{
Stream<myModel> myInfoStream() async*{
yield await dbService.getMyInfo();
}
}
class _aboutStateState extends State<aboutState> {
Stream stream ;
dbManager mng = new dbManager();
@override
void initState() {
// TODO: implement initState
stream = mng.myInfoStream();
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
color: Colors.pink[300],
child: StreamBuilder<myModel>(
stream: stream,
builder: (context, snapshot){
if(snapshot.hasError){
print(snapshot.error);
return Center(child: Text('Something went wrong , please try again later'),);
}
else if(snapshot.hasData){

return Text("${snapshot.data.name}");

}
else {
return Center(child: CircularProgressIndicator());
}
},
),
我收到这个错误
this line to print
[cloud_firestore/unknown] NoSuchMethodError: invalid member on null: 'includeMetadataChanges'
但是当我直接连接到 firestore 而不将其转换为模型时,它工作正常并在屏幕上打印数据,代码:
child:FutureBuilder(
future: me.doc(id).get(),

builder: (context, snapshot){
if(snapshot.hasError){
print(snapshot.error);
return Center(child: Text('Something went wrong , please try again later'),);
}
else if(snapshot.hasData){
// print("${snapshot.data.data()['app_pics'][1]} \n${snapshot.data.data()['img']}");
return Text("${snapshot.data.data()['app_pics'][1]}");

}
else {
return Center(child: CircularProgressIndicator());
}
},
),
我跑 flutter 医生
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, 1.24.0-10.2.pre, on Microsoft Windows [Version 6.3.9600], locale
en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 4.0)
[√] VS Code (version 1.51.0)
[√] Connected device (3 available)

• No issues found!
请我需要帮助
enter image description here

最佳答案

我找到了答案,它是由 Firebase JS SDK 的版本引起的。
我将 index.html 文件中的 8.1.1 替换为 7.22.1

  <!-- The core Firebase JS SDK is always required and must be listed first -->
<!-- <script src="https://www.gstatic.com/firebasejs/8.1.1/firebase-app.js"></script>-->

<!-- &lt;!&ndash; TODO: Add SDKs for Firebase products that you want to use-->
<!-- https://firebase.google.com/docs/web/setup#available-libraries &ndash;&gt;- ->
<!-- <script src="https://www.gstatic.com/firebasejs/8.1.1/firebase-firestore.js">
</script>-->
<!-- <script src="https://www.gstatic.com/firebasejs/8.1.1/firebase-analytics.js"></script>-->
我正在为 使用 7.22.1 版本Firebase JS SDK
<script src="https://www.gstatic.com/firebasejs/7.22.1/firebase-app.js"></script>

<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.22.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.22.1/firebase-analytics.js"></script>

关于firebase - flutter :[cloud_firestore/unknown] NoSuchMethodError: invalid member on null: 'includeMetadataChanges' (Flutter Web),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65001207/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com