Getter Setter

 import "dart:io";

///Getter and Setter: Getters and Setters are special methods that provide read and write access to an object's properties.
///Recall that each instance variable has am implicit getter, plus a setter if appropriate
// void main() {
// var obj = A();
//
// obj.x = 10; // Default setter
//
// stdout.write(obj.x); // Default getter
// }
// class A {
// var x;
// }

/// Creating Custom setter and getter
void main() {
var obj1 = B();

obj1.cusSet = "Hello Rahul !!!"; //set the value "Hello Rahul !!!"
stdout.write(obj1.cusSet); //get the value by printing value
}
class B {
var name; // instance(Global) variable

/// custom setter
void set cusSet(var name) {
this.name = name;
}

/// custom getter
String get cusSet {
return name;
}
}

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter