Eva*_*Pon 2 macos firebase flutter google-cloud-firestore
我有一个简单的 Flutter 项目。它所做的只是连接到 Firestore 集合、提取一些文档并显示它们。这在 iOS 上运行良好。但是,当我尝试在 macOS 中运行它时,我无法检索文档。我没有看到任何例外,只是没有成功。
\n我与最初的默认项目相比唯一改变的是构建方法之一(如下),以及导入\'package:cloud_firestore/cloud_firestore.dart\'.
我的构建方法:
\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n appBar: AppBar(\n title: Text(widget.title),\n ),\n body: StreamBuilder(\n stream: Firestore.instance.collection(\'mycollection\').snapshots(),\n builder: (context, snapshot) {\n if (!snapshot.hasData) return const Text(\'Loading\');\n return ListView.builder(\n itemExtent: 80,\n itemCount: snapshot.data.documents.length,\n itemBuilder: (context, index) => ListTile(\n title: Row(\n children: [\n Expanded(\n child:\n Text(snapshot.data.documents[index].data[\'title\']),\n )\n ],\n )));\n },\n ),\n\n floatingActionButton: FloatingActionButton(\n onPressed: _incrementCounter,\n tooltip: \'Increment\',\n child: Icon(Icons.add),\n ), // This trailing comma makes auto-formatting nicer for build methods.\n );\n }\nRun Code Online (Sandbox Code Playgroud)\n通过阅读,Firebase 似乎并不完全支持 macOS。也就是说,人们似乎已经能够让它发挥作用 - 例如,Swift macOS Firebase。我还发现也许我应该使用FirebaseCorepod,而不是这里Firebase/Core看到的 pod 。当我尝试手动添加Pod 时,看来我仍然拥有该Pod,并且我不明白该机制如何足以将其拉出。FirebaseCoreFirebase/Corepubspec/pods
更多背景:
\n\xe2\x96\xb6 flutter doctor\nDoctor summary (to see all details, run flutter doctor -v):\n[\xe2\x9c\x93] Flutter (Channel master, 1.21.0-1.0.pre, on Mac OS X 10.15.5 19F101, locale en-US)\n[\xe2\x9c\x97] Android toolchain - develop for Android devices\n \xe2\x9c\x97 Unable to locate Android SDK.\n Install Android Studio from: https://developer.android.com/studio/index.html\n On first launch it will assist you in installing the Android SDK components.\n (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).\n If the Android SDK has been installed to a custom location, set ANDROID_SDK_ROOT to that location.\n You may also want to add it to your PATH environment variable.\n\n\n[\xe2\x9c\x93] Xcode - develop for iOS and macOS (Xcode 11.6)\n[\xe2\x9c\x93] Chrome - develop for the web\n[!] Android Studio (not installed)\n[\xe2\x9c\x93] VS Code (version 1.47.0)\n[\xe2\x9c\x93] Connected device (4 available)\nRun Code Online (Sandbox Code Playgroud)\n
我的应用程序处于应用程序沙盒模式,并且没有适当的权利。我可以用两种不同的方式解决这个问题:
将权利添加com.apple.security.network.client到两个权利文件(DebugProfile.entitlements和Release.entitlements,均位于 下macos/Runner。如果我希望能够在 App Store 中发布我的应用程序,这是首选选项。
com.apple.security.app-sandbox我可以通过在相同的权利文件中将权利设置为 false 来关闭应用程序沙盒模式。
在我的案例中,无法发出网络请求的问题被掩盖了,因为如果无法到达云端,Firestore 客户端默认使用本地缓存。因此,就我而言,本地缓存没有数据,我得到的是空响应而不是错误。
有关更多信息,请参阅https://flutter.dev/desktop#entitlements-and-the-app-sandbox 。
| 归档时间: |
|
| 查看次数: |
2242 次 |
| 最近记录: |