Reputation: 1049
I'm trying to make a list with Dart Flutter. I added a button and when I click the button, the item will be deleted from the list. But I need to assign an id to each item in the list. In education, it does not give an error in classes, but it does for me.
class Kisiler {
int id;
String ad;
String soyad;
int numara;
Kisiler.withId(int id, String ad, String soyad, int numara) {
this.id = id;
this.ad = ad;
this.soyad = soyad;
this.numara = numara;
}
Kisiler(String ad, String soyad, int numara) {
this.id = id;
this.ad = ad;
this.soyad = soyad;
this.numara = numara;
}
}
When training:
What is the problem? How can I solve it? I'm creating a list on main.dart with the following code:
Upvotes: 0
Views: 63
Reputation: 174
That is because of null safety.
class Kisiler {
int? id;
late String ad;
late String soyad;
late int numara;
Kisiler.withId(this.id, this.ad, this.soyad, this.numara);
Kisiler(this.ad, this.soyad, this.numara);
}
Upvotes: 1