Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

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);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dart #create #singleton #parameters
ADD COMMENT
Topic
Name
6+3 =