I see this error message which says two things -
- Argument type String cant be assigned to the parameter type 'String'
- 'data' refers to a property so it couldn't be promoted.
For the first error I have added a null check to the code which also doesn't fix issue and for the second one I have no idea what to do with it.
CodePudding user response:
The second error is essentially saying that you can't fix the error only by adding a null check. As you already know, the compiler treats local variable declarations as non-nullable within contexts where it can be inferred that the variable is not null - that type conversion is called "promotion".
The compiler cannot perform promotion on instance properties, however - So even though you've already checked the value, you still need to add a !
on the end to unwrap the value.
if (response.data != null) {
Map<String, dynamic> data = jsonDecode(response.data!);
// Snip
}