什么是@macro飞镖评论?喜欢
/// The application's top-level routing table.
///
/// When a named route is pushed with [Navigator.pushNamed], the route name is
/// looked up in this map. If the name is present, the associated
/// [WidgetBuilder] is used to construct a [MaterialPageRoute] that performs
/// an appropriate transition, including [Hero] animations, to the new route.
///
/// {@macro flutter.widgets.widgetsApp.routes}
final Map<String, WidgetBuilder> routes;
Run Code Online (Sandbox Code Playgroud)
它是 dartdoc 的一部分
https://pub.dev/packages/dartdoc#macros
您可以指定“宏”,即可重复使用的文档。为此,首先在评论中的任何地方指定一个模板,例如:
/// {@template template_name}
/// Some shared docs
/// {@endtemplate}
Run Code Online (Sandbox Code Playgroud)
然后你可以通过插入它{@macro template_name},比如
/// Some comment
/// {@macro template_name}
/// More comments
Run Code Online (Sandbox Code Playgroud)
模板定义当前没有作用域——如果 dartdoc 读取包含模板的文件,它可以用于 dartdoc 当前正在记录的任何内容。这可能会导致在不同包上运行之间的行为不一致,尤其是当 dartdoc 使用不同的命令行时。建议对任何宏使用抗冲突命名,方法是在名称中包含包名称和/或定义它的库。