dart中dartdoc命令的坑

2,884 阅读1分钟

今天在用dartdoc命令的时候,尽管已经配置好了dart环境,但是输入dartdoc命令后,报错了,错误内容如下:

➜  flutter_module_example dartdoc
Documenting flutter_module_example...

dartdoc failed: Top level package requires Flutter but FLUTTER_ROOT environment variable not set.

经过一番查阅,也不知道是什么问题,但是找到了一个解决办法:

If you wish to generate API documentation locally on your development machine, use the following commands:

  1. Change directory to the location of your package:
cd ~/dev/mypackage  
  1. 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   
  1. 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

文档地址:flutter.dev/docs/develo… 中文翻译直接上截图吧

其实在环境环境变量里面配置上$FLUTTER_ROOT也可以,

FLUTTER_ROOT=~/dev/flutter

mac的别忘了source ~/.bash_profile文件,然后执行

$FLUTTER_ROOT/bin/cache/dart-sdk/bin/dartdoc

就可以了。