如何在 Dart 和 Flutter 中创建 DartDoc 宏/模板?

cre*_*not 6 dart flutter dartdoc

我在整个 Flutter 仓库中看到过如下片段:

/// {@macro flutter.widgets.editableText.readOnly}
Run Code Online (Sandbox Code Playgroud)

在 IDE 和渲染的 Dart 文档中,它显示如下

文本是否可以更改。

当此设置为 true 时,文本无法通过任何快捷方式或键盘操作进行修改。文本仍然可以选择。

默认为假。不能为空。

它往往远远超出这个基本情况。

cre*_*not 6

您可以创建模板,并把它们作为使用dartdoc,这是一个带有扑默认的API文档包。

只需@template在文档中的任何位置定义一个:

/// {@template template_name}
/// Some shared docs
/// {@endtemplate}
Run Code Online (Sandbox Code Playgroud)

现在,您可以在其他任何地方重用它:

/// Some comment
/// {@macro template_name}
/// More comments
Run Code Online (Sandbox Code Playgroud)

了解更多