如何在android studio的评论行添加代码引用?

pdkcd3nj  于 2022-11-16  发布在  Android
关注(0)|答案(3)|浏览(157)

我想在注解文档中添加代码参考,如以下屏幕截图。

但我得到的这个结果

我真的很高兴,如果有人指导我一些礼物或有用的链接,我想要的结果。谢谢

qij5mzcb

qij5mzcb1#

我来晚了一点,
因此,链接注解只允许在块之外。
正如你所看到的,第一个是在类的块之外,如果你把你的链接注解放在dart文件中的任何块之外,在其他情况下都能工作,它不会。

///Outside class' block [hello] => THIS WILL WORK
class ClassName {
///Inside class' block [hello] => THIS WON'T WORK

  void hello(){
  }
 
}

希望我能帮上忙:)

guicsvcw

guicsvcw2#

你是否创建了showPartialLoading()showFullScreenLoading()的类型名称?
因为如果用方括号将变量、方法或类型名称括起来,那么dart doc将查找名称并链接到其文档,即使是从同一项目文档中的不同文件。请确保所有标识符都存在,以便可以引用注解。
例如:

///if you control + click this -> [MyApp] it will bring you to MyApp Class name

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

PS:idk为什么在StackOverflow代码预览(markdown)中不显示颜色差异,但如果你在dart文件中运行它,我肯定它能工作。
希望这会有所帮助。
更多信息:
https://dart.dev/guides/language/effective-dart/documentation
https://dart.dev/tools/linter-rules#comment_references
https://youtu.be/zLzlSVD85GA

ttcibm8c

ttcibm8c3#

也许我迟到了,但我希望它能帮助一些人。检查这个减价代码

示例

/// This is a paragraph of regular text.
///
/// This sentence has *two* _emphasized_ words (italics) and **two**
/// __strong__ ones (bold).
///
/// A blank line creates a separate paragraph. It has some `inline code`
/// delimited using backticks.
///
/// * Unordered lists.
/// * Look like ASCII bullet lists.
/// * You can also use `-` or `+`.
///
/// 1. Numbered lists.
/// 2. Are, well, numbered.
/// 1. But the values don't matter.
///
///     * You can nest lists too.
///     * They must be indented at least 4 spaces.
///     * (Well, 5 including the space after `///`.)
///
/// Code blocks are fenced in triple backticks:
///
/// ```dart
/// this.code
///     .will
///     .retain(its, formatting);
/// ```
///
/// The code language (for syntax highlighting) defaults to Dart. You can
/// specify it by putting the name of the language after the opening backticks:
///
/// ```html
/// <h1>HTML is magical!</h1>
/// ```
///
/// Links can be:
///
/// * https://www.just-a-bare-url.com
/// * [with the URL inline](https://google.com)
/// * [or separated out][ref link]
///
/// [ref link]: https://google.com
///
/// # A Header
///
/// ## A subheader
///
/// ### A subsubheader
///
/// #### If you need this many levels of headers, you're doing it wrong

相关问题