我正在尝试在我的根项目中安装flutterfire_cli,所以我输入了这个命令:
FirebaseFirestore firestore = FirebaseFirestore.instance;
在那之后,这是我控制台的输出:
PS C:\Users\PC\Desktop\eventually> dart pub global activate flutterfire_cli
Package flutterfire_cli is currently active at version 0.1.1+2.
Resolving dependencies...
The package flutterfire_cli is already activated at newest available version.
To recompile executables, first run `global deactivate flutterfire_cli`.
Installed executable flutterfire.
Warning: Pub installs executables into C:\Users\PC\AppData\Local\Pub\Cache\bin, which is not on your path.
You can fix that by adding that directory to your system's "Path" environment variable.
A web search for "configure windows path" will show you how.
Activated flutterfire_cli 0.1.1+2.
为了修复警告,我在系统变量环境中的路径中添加了C:\用户\PC\AppData\Local\Pub\Cache\bin。(
接下来,我尝试使用以下命令生成firebase_options. dart文件,如留档所示:
flutterfire configure
但是我在控制台收到一个错误:
PS C:\Users\PC\Desktop\eventually> flutterfire configure
flutterfire : The term 'flutterfire' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ flutterfire configure
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (flutterfire:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
有人能告诉我我错过了什么,为什么我会得到这个错误,即使FirebaseCLI已经安装在我的机器上?
仔细浏览此文档:https://firebase.flutter.dev/docs/cli/
第1步:安装FirebaseCLI
第2步:使用以下命令安装FlutterFireCLIdart pub global激活flutterfire_cli
在执行此操作时,您必须注意以下警告
警告:Pub会将可执行文件安装到不在您路径上的C:\User\PC\AppData\Local\Pub\Cache\bin中。您可以通过将该目录添加到系统的“Path”环境变量中来解决此问题。Web搜索“配置Windows路径”将向您展示如何操作。
这意味着您需要将C:\User\*username*\AppData\Local\Pub\Cache\bin
添加到系统的环境路径中。
对于MacOS运行:导出PATH="$PATH":"$HOME/. pub-cache/bin"
第3步:现在flutterfire confiure
应该可以工作了。
如果仍然无法使用Firebase命令
对于Mac-
导出PATH="$PATH":"$HOME/. pub-cache/bin"
让它在Windows上工作的三个3步骤:
>
运行此命令:
飞镖酒吧全球激活flutterfire_cli
在Windows search中键入env并打开编辑系统环境变量--
C:\用户\放在这里你的用户名\应用数据\本地\Pub\缓存\bin
flutterfire confiure
命令现在应该可以工作了-关闭并再次打开命令提示符或其他终端。有时其他编辑器和终端出现问题,flutterfire confiure
仍然不起作用。在这种情况下,打开命令提示符,它肯定会在那里工作。