class Peoples {
late int id;
late String name;
static final Peoples _inst = Peoples._internal();
Peoples._internal();
factory Peoples() {
return _inst;
}
}
I have this singleton class. Which ensures that, only one instance of a class is ever created. So, even if someone tries to instantiate it, they will use the same instance. And i can create and set values, like:
Peoples ps1 = Peoples();
Peoples ps2 = Peoples();
ps1.id = 1;
ps1.name = "First";
ps2.id = 2;
ps2.name = "Second";
Is it possible to instantiate and set values like:
Peoples ps1 = Peoples(1, "First");
Peoples ps2 = Peoples(2, "Second");
So, now both "ps1" and "ps2" will have (2, "Second").