当前位置:K88软件开发文章中心编程全书编程全书03 → 文章内容

Dart 空白符

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-23 14:02:28

oodclass ListBox { bool showScrollbars; ListBox({this.showScrollbars: false});}main() { new ListBox(showScrollbars: true);}// badnew ListBox(showScrollbars:true);new ListBox(showScrollbars : true);可选位置参数的 = 周围应该空一格。// goodclass HttpServer { static Future<HttpServer> listen([int port = 80]) { // ... }}// badimport 'dart:async';class HttpServer { static Future<HttpServer> listen([int port=80]) { // ... }}方法的级联应该缩进两格。// goodlist = new List() ..addAll([1, 2, 3]) ..addAll([4, 5, 6]);// badlist = new List() ..addAll([1, 2, 3]) ..addAll([4, 5, 6]);以前的时候这条规则是“缩进四格”,但是根据我们对于已有代码的调查结果来看,级联使用两格缩进更加常见。多行列表以及映射的字面值的代码如果采取多行形式,那么应该缩进两行,并且把闭合的 ] 或者 } 放在下一行。多行列表以及映射的字面值最好是在逗号之后换行。] 或者 } 应该根据上下文代码来进行缩进,以匹配上下文代码的格式。// goodvar simpleList = [1, 2, 3];var simpleMap = {'a': 1, 'b': 2, 'c': 3};var fooList = [ 'a', 'b', 'c'];var barMap = { 'a': 'b', 'c': 'd'};var listInsideMap = { 'a': ['b', 'c', 'd'], 'e': [ 'f', 'g', 'h' ]};var mapInsideMap = { 'a': {'b': 'c', 'd': 'e'}, 'f': { 'f': 'g', 'h': 'i' }};var mapInsideList = [ { 'a': 'b', 'c': 'd' }, { 'a': 'b', 'c': 'd' },];// badvar fooList = [ 1, 2, 3];var fooList = [ 1, 2, 3];var fooList = [1, 2, 3, 4];

上一页  [1] [2] 


Dart 空白符