简体   繁体   English

Flutter 和 Dart 文档中的@macro 注释是什么

[英]What is the @macro annotation in Flutter and Dart documentation

When I'm reading the source code I often see something like this (from TextField ):当我阅读源代码时,我经常看到这样的东西(来自TextField ):

/// {@macro flutter.widgets.editableText.keyboardType}
final TextInputType keyboardType;

What does the @macro mean? @macro是什么意思?

I found the answer so I'm posting it below as a self-answer Q&A.我找到了答案,所以我将其作为自我回答问答发布在下面。

A @macro is a way to insert some dartdoc documentation that has been written somewhere else. @macro是一种插入一些在其他地方编写的dartdoc文档的方法。 That way you don't have duplicate docs that you have to maintain.这样您就没有必须维护的重复文档。

The string that follows @macro is the name of a template, which includes the documentation you'll insert. @macro的字符串是模板的名称,其中包括您将插入的文档。 So in the TextField example:所以在TextField示例中:

/// {@macro flutter.widgets.editableText.keyboardType}
final TextInputType keyboardType;

the template name is flutter.widgets.editableText.keyboardType .模板名称是flutter.widgets.editableText.keyboardType If you go to the source code for EditableText , you'll find the template with it's documentation text:如果您转到EditableText的源代码,您将找到带有文档文本的模板:

/// {@template flutter.widgets.editableText.keyboardType}
/// The type of keyboard to use for editing the text.
///
/// Defaults to [TextInputType.text] if [maxLines] is one and
/// [TextInputType.multiline] otherwise.
/// {@endtemplate}
final TextInputType keyboardType;

The annotation @template starts the template and is followed by its name.注释@template启动模板,后跟其名称。 @endtemplate finishes it. @endtemplate完成它。

When you view the documentation for EditableText.keyboardType and TextField.keyboardType , you can see they are exactly the same:当您查看EditableText.keyboardTypeTextField.keyboardType的文档时,您会发现它们完全相同:

Read more in the dartdoc documentation .dartdoc 文档中阅读更多内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM