20

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.

Shahzad Akram
  • 4,586
  • 6
  • 32
  • 65
  • 2
    Are you sure that `FLUTTER_ROOT` is set? From the same terminal where you ran `dartdoc`, does `echo $FLUTTER_ROOT` print anything? Related: https://github.com/flutter/flutter/issues/24808 – jamesdlin Apr 07 '20 at 18:41
  • Thanks, I solved it, actually, I only added the flutter path but not `FLUTTER_ROOT` environment variable. – Shahzad Akram Apr 11 '20 at 09:04
  • If someone has landed here searching a solution for Windows (my case) just got to the properties of the pc and add the environment variable directly. Close and open your terminal :D – FJBatresV May 23 '20 at 05:17

2 Answers2

19

try running flutter pub global run dartdoc:dartdoc instead

Qiong Wu
  • 1,504
  • 1
  • 15
  • 27
9

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/resources/dartdoc   # on macOS or Linux  
%FLUTTER_ROOT%\bin\cache\dart-sdk\bin\resources\dartdoc   # on Windows

link https://flutter.dev/docs/development/packages-and-plugins/developing-packages

Arun Prakash
  • 123
  • 1
  • 12
Wizz.Xu
  • 101
  • 1
  • 2