-1

enter image description here

Error: A value of type 'Employee?' can't be assigned to a variable of type 'Employee' because 'Employee?' is nullable and 'Employee' isn't.

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
Ah Hea Sk
  • 13
  • 1
  • 2
  • 4
  • The error is pretty straightforward. Where you have defined your employee member, you have declared it to not be nullable (without the question mark (?)). In the code you posted, you are either going to assign it a value or not and that is why you are seeing the compiler warning. Based on your logic, decide if it can be nullable or not and act appropriately. – tomerpacific Dec 17 '21 at 05:34

1 Answers1

1

.fromJson constructor your employee varable can be null as your initing it, but in model it declare like null safaty(by default). If your logic is requider this varible strongly, be shure is not null. Other way if it is not required you can use ? brfore class name, then it can be null!

Employee? employee;