首页 > 解决方案 > Dart @macro 在评论中

问题描述

@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;

标签: flutterdart

解决方案


它是 dartdoc 的一部分

https://pub.dev/packages/dartdoc#macros

您可以指定“宏”,即可重复使用的文档。为此,首先在评论中的任意位置指定一个模板,例如:

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

然后你可以通过 插入它{@macro template_name},比如

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

模板定义目前没有作用域——如果 dartdoc 读取包含模板的文件,它可以用于 dartdoc 当前正在记录的任何内容。这可能会导致在不同包上运行之间的行为不一致,尤其是当 dartdoc 使用不同的命令行时。建议对任何宏使用防冲突命名,方法是在名称中包含包名称和/或定义它的库。


推荐阅读