Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The class I specified for the item delete button from the list in Dart Flutter gives an error

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;
  }
}

While I do:
enter image description here

When training:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

What is the problem? How can I solve it? I’m creating a list on main.dart with the following code:

>Solution :

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);
} 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading