Home > OS >  Error using amplify_api package inside flutter app, says property couldn't be promoted
Error using amplify_api package inside flutter app, says property couldn't be promoted

Time:05-24

I see this error message which says two things -

  1. Argument type String cant be assigned to the parameter type 'String'
  2. 'data' refers to a property so it couldn't be promoted.

enter image description here

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
}
  • Related