-1
In the code I’m doing, is being mounted an if to know if a certain age is greater or smaller and show the messages, so far so good.
The point is, when I use the integer value, I can work normally, but when I enable the input to inform the value in the input, it shows me this message:
Error: The argument type 'String? ' can’t be Assigned to the Parameter type 'String' because 'String? ' is nullable and 'String' isn’t..
I know this giving a string to integer conversion error, but I’ve looked for other ways, using int.tryParse
, int.parse
(which is what shows in the course and the video works), inform the value already with int, but none of the ones I tried works.
I would like some help if you could just let me know what I’m missing or what else I could read to get an idea of why it’s not working.
Code:
import 'dart:io';
main() {
print("==== Digite uma idade ====");
var input = stdin.readLineSync();
var idade = int.parse(input);
if (idade >= 18) {
print("Maior de Idade");
} else {
print("Menor de Idade");
}
}
Thank you in advance.
You tried to create int variables instead of var?
– Renan