Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create DartDoc Macros/Templates in Dart and Flutter?

I have seen snippets like the following throughout the Flutter repo:

/// {@macro flutter.widgets.editableText.readOnly}

In the IDE and in the rendered Dart docs, it is then shown like this:

Whether the text can be changed.

When this is set to true, the text cannot be modified by any shortcut or keyboard operation. The text is still selectable.

Defaults to false. Must not be null.

And it tends to go way beyond this basic case.

like image 710
creativecreatorormaybenot Avatar asked Jul 06 '20 20:07

creativecreatorormaybenot


People also ask

How do I add documents to dart?

You document a library by placing a doc comment right above the library directive at the start of the file. If the library doesn't have a library directive, you can add one just to hang the doc comment off of it.

How do you write comments in darts?

Dart Single line Comment: Dart single line comment is used to comment a line until line break occurs. It is done using a double forward-slash (//). // This is a single line comment.

How do you add comments on flutter?

Just select the lines you want to make comment with your mouse, then press the following key combination: Ctrl + K then press Ctrl + C if you're using Windows.

How to change how dartdoc generates documentation for a dart element?

dartdoc will not generate documentation for a Dart element and its children that have the @nodoc tag in the documentation comment. Creating a file named dartdoc_options.yaml at the top of your package can change how Dartdoc generates docs. An example (not necessarily recommended settings):

How do I open a dart DOC file?

By default, the documentation is generated to the doc/api directory as static HTML files. Run dartdoc -h to see the available command-line options. You can view the generated docs directly from the file system, but if you want to use the search function, you must load them with an HTTP server.

Why do Dart classes have so few keywords?

Fewer language keywords means less clutter, and in this case, readability is not sacrificed. You create a Dart class constructor by adding a class method with the same name as the class itself. Often, constructors take parameters to initialize member variables:

Is Dart a functional programming language?

The Dart language has great support for functional programming, but it's also a pure object-oriented (OO) language with single inheritance and mixin support. Even literals are objects, allowing you to write code like 5.isOdd, which will resolve to true.


Video Answer


1 Answers

You can create templates and use them as macros using dartdoc, which is the default API documentation package that comes with Flutter.

Simply define an @template anywhere in your docs:

/// {@template template_name}
/// Some shared docs
/// {@endtemplate}

Now, you can reuse it anywhere else:

/// Some comment
/// {@macro template_name}
/// More comments

Learn more.

like image 83
creativecreatorormaybenot Avatar answered Oct 18 '22 09:10

creativecreatorormaybenot