When I try to create a constructor in dart like Student(this._name)
it doesn't work with private variables.
I have already tried using setters but it doesn't work either.
class Student{
var _id;
var _name;
Student(this.id, this.name);
void set id(int id) => _id = id;
void set name(String name) => _name = name;
}
Student({this._id, this._name});
would not be allowed)var
.var
is fine for local variables that are initialized when declared. Don't use public getters/setters for private fields if they don't contain additional logic. You can replace fields by getters/setters or vice versa at any time without breaking users of your code.