This code is from flutter gallery and i'm trying to understanding and adapting it. I would know what this syntax means:
class DemoItem<T> {
DemoItem({
this.valueName,
this.hintName,
this.valueSurname,
this.hintSurname,
this.builder,
this.valueToString
}) : textController = new TextEditingController(text: valueToString(valueName));
Especially i would know what means the colon after the constructor and if there is a way to define another TextEditingController, in addition to the one already defined.
Thank you in advance.
The part after :
is called "initializer list. It is a ,
-separated list of expressions that can access constructor parameters and can assign to instance fields, even final
instance fields. This is handy to initialize final fields with calculated values.
The initializer list is also used to call other constructors like : ..., super('foo')
.
Since about Dart version 1.24 the initializer list also supports assert(...)
which is handy to check parameter values.
The initializer list can't read from this
because the super constructors need to be completed before access to this
is valid, but it can assign to this.xxx
.