简体   繁体   English

Dart/Flutter 防止格式化程序将方法调用压缩到一行

[英]Dart/Flutter prevent formatter from squashing method calls to one line

my formatter keeps doing such a thing.我的格式化程序一直在做这样的事情。 When I try to place method calls in separate lines.当我尝试将方法调用放在单独的行中时。 For example I have such a code:例如我有这样的代码:

main() {
  SomeObject()
    .someMethod()
    .someMethodWithArgument('someArgument')
    .someMethodWithArgument('someOtherArgument');
}

After hitting quick format, I get something like that:点击快速格式化后,我得到了类似的东西:

main() {
  SomeObject().someMethod().someMethodWithArgument('someArgument')
    .someMethodWithArgument('someOtherArgument');
}

It drives me crazy and it is totally unreadable in my opinion.它让我发疯,在我看来这是完全不可读的。 I played around with format settings in Android Studio preferences but I cannot find anything that would fix this particular formatting issue.我在 Android Studio 首选项中尝试了格式设置,但找不到可以解决此特定格式问题的任何内容。

There's no way to configure dartfmt by design.无法按设计配置dartfmt However, you can technically force it to match the formatting you have using comments on each line:但是,您可以在技术上强制它使用每一行的注释来匹配您的格式:

main() {
  SomeObject() //
    .someMethod() //
    .someMethodWithArgument('someArgument') //
    .someMethodWithArgument('someOtherArgument');
}

It's obviously not ideal, and won't be consistent with other Dart code in the ecosystem, but if the formatting bothers you that much it's the only option.这显然不理想,并且与生态系统中的其他 Dart 代码不一致,但如果格式如此困扰您,那么它是唯一的选择。

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

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