本文介绍了如何使Dartfmt变得“友好”?矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于应该是这样的矩阵:

For a Matrix that supposed to look like this:

const ColorFilter sepia = ColorFilter.matrix(<double>[
          0.393, 0.769, 0.189, 0, 0,
          0.349, 0.686, 0.168, 0, 0,
          0.272, 0.534, 0.131, 0, 0,
          0,     0,     0,     1, 0,
        ]);

但是dartfmt将其更改为:

But dartfmt changed it to become like this:

const ColorFilter sepia = ColorFilter.matrix(<double>[
          0.393,
          0.769,
          0.189,
          0,
          0,
          0.349,
          0.686,
          0.168,
          0,
          0,
          0.272,
          0.534,
          0.131,
          0,
          0,
          0,
          0,
          0,
          1,
          0,
        ]);

这很难看懂。因此,如何保持原始格式,以便可以更友好地看到Matrix。还是至少我该如何使Dartfmt不重新格式化任何列表?

This is hard to read. Thus, how can I keep the original format so that the Matrix can be seen more "friendly". Or at least how can I make Dartfmt not to reformat any List?

推荐答案

在dart_style的FAQ中对这种情况进行了说明,其中dartfmt基于以下内容:

This scenario is described in the FAQ of dart_style which dartfmt is based on:

简而言之,您只需要在矩阵定义中的某处添加注释,例如:

In short, you just need to add a comment somewhere in you matrix definition like:

const ColorFilter sepia = ColorFilter.matrix(<double>[
          0.393, 0.769, 0.189, 0, 0, //
          0.349, 0.686, 0.168, 0, 0,
          0.272, 0.534, 0.131, 0, 0,
          0,     0,     0,     1, 0,
        ]);

然后dartfmt将不会尝试在矩阵中设置换行符的格式。但是,它将仍然修复不需要的空格,因此它将使您的示例变为:

Then dartfmt will not try to format the newlines in the matrix. It will however, still fixes non-needed spaces so it will make your example into:

const ColorFilter sepia = ColorFilter.matrix(<double>[
  0.393, 0.769, 0.189, 0, 0, //
  0.349, 0.686, 0.168, 0, 0,
  0.272, 0.534, 0.131, 0, 0,
  0, 0, 0, 1, 0,
]);

可以通过将0更改为0.000来固定:

Which can be fixed by changing the 0 to 0.000:

const ColorFilter sepia = ColorFilter.matrix(<double>[
  0.393, 0.769, 0.189, 0, 0, //
  0.349, 0.686, 0.168, 0, 0,
  0.272, 0.534, 0.131, 0, 0,
  0.000, 0.000, 0.000, 1, 0,
]);

这篇关于如何使Dartfmt变得“友好”?矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 11:02