First of, sorry for the title name. I’m not sure how else to ask this.
In swift, we can run the following code:
func setColor(to newColor: UIcolor) {
self.color = newColor
}
setColor(to: .blue)
In dart, the only ways I know of doing that code is:
setColor(Color newColor){
this.color = newColor;
}
setColor(Colors.blue);
Or
setColorTo({Color newColor}){
this.color = newColor;
}
setColorTo(newColor: Colors.blue);
To me, the swift code is much cleaner. I personally like it when the code explains what is happening. E.g setColor(to: color)
.
I like it when you can choose one name for the code and another for the usage.
If you are to call setColor(color)
, you know what it is doing but is further away from normal English. You could also do setColorTo(newColor: color)
but the word ‘to’ shouldn’t be in the function. Also calling it newColor
makes it more verbose as it fits with the code and when calling the function.
Is there a way to use swift like syntax in dart?