I'm trying to generated proto file to dart file with protoc-plugin follow this instruction https://grpc.io/docs/quickstart/dart/ but when I run this command line
protoc --dart_out=grpc:lib/proto --plugin=protoc-gen-dart=C:/src/flutter/flutter/.pub-cache/bin/protoc-gen-dart.bat -Iprotobuf protobuf/utils.proto
And it showed this error:
'dart' is not recognized as an internal or external command,
operable program or batch file.
'pub' is not recognized as an internal or external command,
operable program or batch file.
--dart_out: protoc-gen-dart: Plugin failed with status code 1.
I have installed dart as a plugin in my Android Studio. Is that I have to install dart SDK and add it to environment variable path to work?
Update
It worked after i install dart sdk and restart my pc.
Seeing the Flutter tag, I presume that Flutter SDK was what you had before you install Dart SDK as said in your update.
If you want to do this without having to install Dart SDK separately (since Flutter SDK has Dart SDK within itself already), the environment has to know where the following are at:
Flutter SDK
eg: export PATH="~/desktop/development/flutter/bin:$PATH"
Dart SDK within Flutter SDK
eg: export PATH="~/desktop/development/flutter/bin/cache/dart-sdk/bin:$PATH"
Pub cache within Flutter SDK (where the protoc plugin will be located at)
eg: export PATH="$PATH":"$HOME/desktop/development/flutter/.pub-cache/bin"
The given examples above are from .bash_profile in macOS, but in essence, the environment has to know where these 3 are before trying to globally activate the plugin via flutter pub global activate protoc_plugin and then generate Dart code from proto files.
The file protoc-gen-dart.bat actually has bugs in it. It's trying to run exe called pub which doesn't exist. You need to manually edit the file. It should be
dart pub global run protoc_plugin:protoc_plugin %*
not
pub global run protoc_plugin:protoc_plugin %*
Once I changed this, I was able to generate protos for Dart on Windows
Related
im trying to install the get_cli package for flutter.
install command is pub global activate get_cli, however pub is not a global variable on my windows 10 machine.
i think i need to add variables to the system environment variables, but i'm not sure what paths and how to call them.
this answer works for unix, so im looking for something similar for windows.
anyone got an idea?
edit: error: 'pub' is not recognized as an internal or external command, operable program or batch file.
If you have Flutter in C:\src\flutter, you can add path variable: C:\src\flutter\bin\cache\dart-sdk\bin (if you have Flutter in another localization, just replace the beginning of the path analogically) and restart your command line tool (or IDE).
You can add flutter prefix before pub as well: flutter pub global activate get_cli - according to flutter -h:
flutter pub - pass the remaining arguments to Dart's "pub" tool
Use dart pub not pub only and it should resolve your problem
enjoy
use flutter pub and make sure the path variable is C:\flutter\bin supposing the Flutter folder is located at C:\flutter
make sure you set the environment variables correctly.After that don't forget to restart the computer. I struggled with this issue for a long time but after doing all these things a magic code worked for me . Which you guys can also try.
dart pub global activate get_cli
then use
flutter pub global activate get_cli
this should work .
I am trying to install the flutter version manager to switch the flutter version among the different flutter projects.
I use the command to install the fvm - pub global activate fvm
but when I run the command on the terminal - fvm help
There is an error -bash: fvm: command not found
How to fix it ?
Your .pub-cache binaries are not yet added to your PATH variable, used by your terminal. Add path with the following command:
export PATH="$PATH:$HOME/.pub-cache/bin"
This is the location where fvm is installed. So by exporting this path to your PATH variable you should be able to get fvm working from anywhere in your terminal.
If you installed fvm using pub and you already have it in your path but you are still getting the error, follow these steps:
run dart pub cache repair // You may get an error: Failed to precompile fvm:main:. Just ignore that for now.
run dart pub global activate fvm
you can do a
flutter clean
then when its done, run
dart pub global activate fvm
when it's done it should work now, close the current bash terminal and open a new one
You must add the path to the fvm executable to the $PATH environment variable. After running "pub global activate fvm" you should have seen a warning with instructions on how to fix it. You can watch this: https://youtu.be/R6vKde1vIGQ
That will get you up and running.
if use windows 10 or later add system properties -> Environment Variables -> Path -> %USERPROFILE%\AppData\Local\Pub\Cache\bin
First confirm if fvm.bat is executing successfully, you should have the folder already in environment variable PATH(%USERPROFILE%\AppData\Local\Pub\Cache\bin). If it is then for fvm to run in bash, instead of fvm.bat, you need to create a shortcut, a file named fvm with no extension, the containing folder should also exist in PATH variable, the file contains location to fvm.bat and ends with a whitespace and S*.
So I'm currently following a tutorial on flutter and it showed this nifty way of running dart code in the same project by creating the new file in the app directory instead of the lib folder. I'm using VS code and can't really figure out how to run the file (they used Android Studio). I tried running the file in the terminal and it kept saying
./scratch.dart: line 1: syntax error near unexpected token `('
./scratch.dart: line 1: `void main() {'
Any idea what I'm doing wrong?
Run dart in terminal to Check that you have dart installed globally with global environment variable in your terminal. If not follow this doc to install https://dart.dev/get-dart.
After making sure that you have dart SDK installed globally in your PC, you can run any dart file containing a void main function in a terminal like
~$ dart path_to_file/scratch.dart
Note: Running un terminal will not work if you are working with a package that utilize dart:ui
I just added the the fvm package to switch the flutter channel from stable to master without downloading sdk components every time when switching flutter channels.
I have followed the step written in readme.md for switching the channel.
I have set the following path in my environment variables.
D:\Program_Files\FlutterSDK\SDK\flutter\bin;
D:\Program_Files\FlutterSDK\SDK\dart-sdk\bin;
C:\Users\User\AppData\Roaming\Pub\Cache\bin;
Now, i have opened my first project in which i want to use "flutter SDK's master channel". But, whenever i try to use the command "fvm use master". It's not working.
It is giving me an error like,
'fvm' is not recognized as an internal or external command,
So, can anyone suggest a solution?
Thanks.
try :
pub global run fvm:main
pub global run fvm:main use VERSION
Hi adding in your path:
%LOCALAPPDATA%\Pub\Cache\bin
More info:
https://dart.dev/tools/pub/cmd/pub-global#running-a-script-from-your-path
In my case fvm commands did not work on Windows even tho I checked everything. It gave missing fvm.exe file and other errors. If you also stuck there you can use this way. Only way I managed to get it work is to use longer commands like these:
flutter pub global run fvm:main list
Seems like all fvm commands:
config Set configuration for FVM
flutter Proxies Flutter Commands
install Installs Flutter SDK Version
list Lists installed Flutter SDK Version
releases Lists Flutter SDK releases.
remove Removes Flutter SDK Version
use Which Flutter SDK Version you would like to use
version Prints the currently-installed version of FVM
Works like this, you just need to add the fvm command to the ending of this - flutter pub global run fvm:main. So add any of them like this form:
flutter pub global run fvm:main releases
flutter pub global run fvm:main install 2.2.0
flutter pub global run fvm:main use 2.2.0
are you add "C:\flutter\bin\cache\dart-sdk\bin" to path?
if you in windows you should run your text editor as administrator as following
In my case Error Message was
Usage Error: Flutter version null is not installed
To fix this:
I have activated FVM by pub global activate fvm;
Printed installed fvm list by fvm list, it should give result as the image below:
Selected which Flutter SDK version to use by running fvm use 1.22.0 (in my case 1.22.0, it may differ according to your desired version) command, It will download SDK if it is not installed yet;
Now you can check is flutter running in your project by running flutter;
Also, you can check if the Flutter SDK version set by calling again fvm list.
The tick means, that version is running in your project.
I am trying to run dartdoc for my flutter package but I am getting this,
dartdoc failed: Top level package requires Flutter but FLUTTER_ROOT environment variable not set.
How to add FLUTTER_ROOT environment variable as I have already added environment variable for Flutter SDK and that's working fine, I am just getting issue while running dartdoc. I am a Linux user.
try running flutter pub global run dartdoc:dartdoc instead
If you wish to generate API documentation locally on your development machine, use the following commands:
Change directory to the location of your package:
cd ~/dev/mypackage
Tell the documentation tool where the Flutter SDK is located (change the following commands to reflect where you placed it):
export FLUTTER_ROOT=~/dev/flutter # on macOS or Linux
set FLUTTER_ROOT=~/dev/flutter # on Windows
Run the dartdoc tool (included as part of the Flutter SDK), as follows:
$FLUTTER_ROOT/bin/cache/dart-sdk/bin/dartdoc # on macOS or Linux
%FLUTTER_ROOT%\bin\cache\dart-sdk\bin\dartdoc # on Windows
link https://flutter.dev/docs/development/packages-and-plugins/developing-packages