代码格式化
As Effective Dart says, when it comes to things like formatting,arguments about which is better are subjective and impossible to resolve.What we do know is that being consistent is objectively helpful.If two pieces of code look different it should be becausethey are different in some meaningful way.When a bit of code stands out and catches your eye, it should do so for a useful reason.
Fortunately, you can use the dartfmt tool —from the command line or in your favorite Dart-savvy IDE —to perform most of the drudge work of formatting your code.For example, here’s how to format all the Dart filesunder the current directory’s bin
, lib
, and test
directories:
$ dartfmt -w bin lib test
However, dartfmt can’t do it all.To avoid making changes that might be unsafe, dartfmt affects only whitespace.For additional guidance, see the Effective Dartstyle guidelines, especially the formatting guidelines.
More information: