Flutter: What is Dart-doc?

Hussain Habibullah
Flutter Community
Published in
3 min readJun 19, 2022

Documenting your code is considered one of the best practices, and especially if you’re managing a production-level app then it’s really important to have documentation of the entire code base. It helps reduce the onboarding costs of new developers and helps other developers understand the functionality, features, coding structure, and logic involved.

Documenting classes and functions:

Documenting your dart code is really easy, you just have to add your documented sentences after ///, and it will be shown whenever you hover over that class or function.

This image below explains to you how:

Interestingly, it accepts markdown and you can even make links in your comments to other classes. Look at this detailed guide for more.

Fun fact: VsCode displays markdown much better than Android Studio.

I did some formatting using markdown, here is how it looks on VsCode:

Generating API Reference Documentation:

Have you ever seen this dart documentation? Ever wondered how this is created?

Flutter provides you a command to create this documentation for your dart code base, in just a minute. Use these commands to generate one for yourself:

flutter pub global activate dartdoc
flutter pub global run dartdoc .

The . means, the entire code should be documented, if you want a specific file then you can replace . with a specific file name.

It will generate a doc directory in your code base, you can open index.html and have a glance at your generated documentation.

It’s all .html after all, and you are free to modify it as you want.

When you are creating packages for pub.dev, it is really important to include API reference documentation along with the code that explains your package properly. You may read more about that here.

Thank you for reading, give it a clap if you liked it.

I am open to freelance, full-time, or part-time roles, feel free to reach out at Linkedin, thank you!

--

--