Emir Bolat
Emir Bolat

Reputation: 1049

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:

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:

Upvotes: 0

Views: 63

Answers (1)

Surajit Mondal
Surajit Mondal

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

Related Questions