How to automatically generate header comments for dart functions in Android Studio?

2,323

Unfortunately, Dart doesn't follow a same convention as Java/Kotlin.

There is a guideline on Effective Dart about documentation that states:

The convention in Dart is to integrate that into the description of the method and highlight parameters using square brackets.

where word that refers to "...verbose tags and sections to describe what the parameters and returns of a method are". Documentation should be written in prose.

So this Java method documentation:

/// Defines a flag with the given name and abbreviation.
///
/// @param name The name of the flag.
/// @param abbr The abbreviation for the flag.
/// @returns The new flag.
/// @throws ArgumentError If there is already an option with
///     the given name or abbreviation.
Flag addFlag(String name, String abbr) => ...

is equivalent to this in Dart:

/// Defines a flag.
///
/// Throws an [ArgumentError] if there is already an option named [name] or
/// there is already an option using abbreviation [abbr]. Returns the new flag.
Flag addFlag(String name, String abbr) => ...

To use Dart Documentation Comments, type /// and press Enter.

Share:
2,323
Dhalloo
Author by

Dhalloo

Updated on December 15, 2022

Comments

  • Dhalloo
    Dhalloo over 1 year

    As we can add header comments by typing /** + Enter in Android Studio for Kotlin / Java functions. Is there any shortcut or plugin available to generate the comments for the dart of flutter?

    • Dinko Pehar
      Dinko Pehar over 4 years
      Hi @Dhalloo if my answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this.
  • Ashik Azeez
    Ashik Azeez about 4 years
    /// Documentation comments /// These allow to reference types or variables via [square-brackets] vogella.com/tutorials/Dart/article.html#comments
  • Dinko Pehar
    Dinko Pehar about 4 years
    Yes, I provided that example with square brackets. However, there is no option to generate documentation as in Java based on method parameters. Dart uses prose form of writing, you have to write documentation by yourself.