如何解决Flutter和Dart文档中的@macro注释是什么
在阅读源代码时,我经常会看到类似的内容(来自TextField):
/// {@macro flutter.widgets.editableText.keyboardType}
final TextInputType keyboardType;
@macro
是什么意思?
我找到了答案,所以我将其发布在下面作为自我解答。
解决方法
@macro
是一种插入一些在其他地方编写的dartdoc文档的方法。这样,您就不必维护重复的文档。
@macro
之后的字符串是模板的名称,其中包括您要插入的文档。因此,在TextField示例中:
/// {@macro flutter.widgets.editableText.keyboardType}
final TextInputType keyboardType;
模板名称为flutter.widgets.editableText.keyboardType
。如果您转到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;
注释@template
将启动模板,后跟其名称。 @endtemplate
完成。
当您查看EditableText.keyboardType
和TextField.keyboardType
的文档时,您会发现它们是完全相同的:
- https://api.flutter.dev/flutter/widgets/EditableText/keyboardType.html
- https://api.flutter.dev/flutter/material/TextField/keyboardType.html
在dartdoc documentation中了解更多信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。