Summary
class Div {
String className;
List children;
Div({this.className, this.children}); // boilerplate
}
class H1 {
List children;
H1({this.children}); // boilerplate
}
var dom =
new Div(className: 'section', children: [ // noisy new
new H1(children: ['Title']), // noisy new
new Div(className: 'sectionbody', children: [ // noisy new
'This is the section body'
])
]);
class Div {
String className;
List children;
}
class H1 {
List children;
}
var dom =
Div { className: 'section', children: [
H1 { children: ['Title']},
Div { className: 'sectionbody', children: [
'This is the section body'
]}
]};
class StockRow extends StatelessWidget {
StockRow({
Stock stock,
this.onPressed,
this.onDoubleTap,
this.onLongPressed
}) : this.stock = stock, super(key: new ObjectKey(stock));
/* StockRow({}) is a explicit definition of "default" constructor to specify initialization list. In addition, implicit "this.stock" must be able to be referred in initialization list as "stock" */
class StockRow extends StatelessWidget {
StockRow({}): super(key: new ObjectKey(stock));
class MyClass {
final int _myInt;
const MyClass(this._myInt);
}
class MyClass {
MyClass({param1, param2, param3}) { ... }
}
// Before ...
var instance = new MyClass(
param1: 0,
param2: 0,
param3: 0
);
// After
var instance = MyClass {
param1: 0,
param2: 0,
param3: 0
};
class MyClass {
MyClass(param1, param2, param3) { ... }
}
// Before
var instance = new MyClass(0, 0, 0)
..var1 = 1
..var2 = 2
..var3 = 3;
// After
var instance = MyClass(0, 0, 0) {
var1: 1,
var2: 2,
var3: 3
}
Currently, if we forget to initialize any final field in any constructor, it's an error.
With "Map-like class literal", it would delay the error until invocation.
I often work with const classes that have constructor parameters that are not publicly available after initialization.
I would have to declare that I expect an extra argument in the Map-like literal.
const ClassName { member1: const1, member2: const2 }
How would we declare internal fields initialization?
(Not much of an improvement).
Removing the "new" keyword would make a huge difference by itself.