Answers for "dart create singleton with parameters"

0

dart create singleton with parameters

class Peoples {
  int id;
  String name;

  static final Peoples _inst = Peoples._internal();

  Peoples._internal();


  factory Peoples(int id, String name) {
    _inst.id = id;
    _inst.name = name;
    return _inst;
  }
}

void main() {
  print("Instance of = " + Peoples(0, "Dylan").name);
  print("Instance of = " + Peoples(1, "Joe").name);
  print("Instance of = " + Peoples(2, "Maria").name);
}
Posted by: Guest on March-16-2022

Code answers related to "Dart"

Browse Popular Code Answers by Language