79436365

Date: 2025-02-13 13:50:45
Score: 0.5
Natty:
Report link

You get the error: "The argument type 'double?' can't be assigned to the parameter type 'double'." Because double.tryParse() returns nullable double (double?) "meaning it can be null if parsing fails" And the parameter is type is non-nullable double (double) "meaning it always has a value and never can be null".

To fix this you have 2 options:

  1. Choose a value to be used in case of null: double x = double.tryParse('1.23') ?? 0.0; Here the double x won't be null even if double.tryParse() returns null the value 0.0 will be used.

  2. Use null assertion operator (!) since you checked if enteredStartingMiles == null and handled that case, in the following lines of code you can say "trust me enteredStartingMiles is not null" by adding (!) at the end of variable name enteredStartingMiles!

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Mahmoud Alawady