简体   繁体   English

升级到 Flutter 2.0 中断 flutter firebase web 项目

[英]Upgrading to Flutter 2.0 breaks flutter firebase web project

I had a full working project and updated flutter to 2.0 and also the full project to null safety.我有一个完整的工作项目并将 flutter 更新为 2.0,并将完整的项目更新为 null 安全。

Now the very first and basic step of getting data from firebase is not working for web.现在,从 firebase 获取数据的第一步和基本步骤不适用于 web。

@override
void initState() {
super.initState();
appState = AppState.loading;
loadData();
}

void loadData() async {
QuerySnapshot val = await FirebaseFirestore.instance
    .collection(FirestoreFields.APPDATA_COLLECTION)
    .get();
setState(() {
  if (val.docs.length == 0)
    appState = AppState.databaseSetupPending;
  else
    appState = AppState.databaseDownloading;
});
}

This code give me following error on flutter for web.此代码在 web 的 flutter 上给了我以下错误。

Error: [cloud_firestore/unknown] Expected a value of type '((Object?) => Object)?', but got one of type '(Object) => Object?'
    at Object.throw_ [as throw] (http://localhost:60662/dart_sdk.js:5032:11)
    at collection_reference_web.CollectionReferenceWeb.new.get (http://localhost:60662/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:370:23)
    at get.next (<anonymous>)
    at http://localhost:60662/dart_sdk.js:37210:33
    at _RootZone.runUnary (http://localhost:60662/dart_sdk.js:37081:59)
    at _FutureListener.thenAwait.handleValue (http://localhost:60662/dart_sdk.js:32337:29)
    at handleValueCallback (http://localhost:60662/dart_sdk.js:32864:49)
    at Function._propagateToListeners (http://localhost:60662/dart_sdk.js:32902:17)
    at _Future.new.[_completeWithValue] (http://localhost:60662/dart_sdk.js:32750:23)
    at async._AsyncCallbackEntry.new.callback (http://localhost:60662/dart_sdk.js:32771:35)
    at Object._microtaskLoop (http://localhost:60662/dart_sdk.js:37333:13)
    at _startMicrotaskLoop (http://localhost:60662/dart_sdk.js:37339:13)
    at http://localhost:60662/dart_sdk.js:33110:9

But same projects runs perfectly on my android device.但同样的项目在我的 android 设备上运行完美。

All my other projects which dont use firebase are also running perfectly on web after updating and making them null safe.我所有其他不使用 firebase 的项目在更新并使其安全后在 web 上也可以完美运行。

This is my index.html file:这是我的 index.html 文件:

https://developers.google.com/web/fundamentals/primers/service-workers -->
  <script src="https://www.gstatic.com/firebasejs/8.2.10/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.2.10/firebase-auth.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.2.10/firebase-firestore.js"></script>
  <script>
    // Your web app's Firebase configuration
    // For Firebase JS SDK v7.20.0 and later, measurementId is optional
    var firebaseConfig = {
      apiKey: "*******************************",
      authDomain: "*******************************",
      projectId: "*******************************",
      storageBucket: "*******************************",
      messagingSenderId: "*******************************",
      appId: "**************************************************************",
      measurementId: "*******************************"
    };
    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);
  </script>

This might be helpful这可能会有所帮助

To see a full list of available changes, run the following command:要查看可用更改的完整列表,请运行以下命令:

dart fix --dry-run

To apply all changes in bulk, run the following command:要批量应用所有更改,请运行以下命令:

dart fix --apply

check the docs https://flutter.dev/docs/development/tools/flutter-fix检查文档https://flutter.dev/docs/development/tools/flutter-fix

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

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