What does ..
mean in dart language in flutter projects?
consider following examples:
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 1000),
vsync: this
)..repeat();
// ^^ here
CodePudding user response:
It is called cascade operator, which can be read about in official doc
In simple form, it says that invoke that method, but instead of returning the return value of method return the reference for the object (class), it is invoked on.
Here although repeat
is going to run on AnimationController
it will return the AnimationController
reference to be stored in _controller
. It allows to access and invoke another method of AnimationController
in other parts that got access to _controller
CodePudding user response:
Its called cascade operator
You can set properties like this
For Example, You can use cascade operator like this, It improves readability
class User {
double? id;
String? name;
}
User user = User();
user.id = 5;
user.name = 'Maverick';
User user2 = User();
user2
..id = 6
..name = 'Kenny';
User user3 = User()..id = 7
..name = 'Roger';
print(user3.name); // prints Roger