skip to Main Content

I am getting this error when i use Radio Button.

int _value = 1;
error: A value of type 'int?' can't be assigned to a variable of type 'int'. (invalid_assignment at [coacum_01] lib/match_screen.dart:450)

enter image description here

enter image description here

Honestly i don’t know what to do, so i did not tried any thing.What can i try?

2

Answers


  1. You can make _value nullable, by doing int? _value = 1;, or you can guarantee that val has a value when you setState, by doing _value = val ?? -1; which will set _value to -1 if val == null.

    Login or Signup to reply.
  2. It’s due to null safety.
    You are trying to assign a nullable integer int? to a non-nullable integer int, which is not allowed in Dart.
    To solve this error, you can either change the data type of the variable val to int to make it non-nullable, or make sure that the value being assigned to _value is not null using _value = val!
    Alternatively, you can use the null-aware assignment operator ??= to assign a default value to _value in case it is null, like this: _value = val ?? 0
    (only if datatype is int?)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search