Text(
data?["success"] != null ? "Success" : "Failure",
style: TextStyle(
color: data?["success"] ? Colors.green : Colors.red,
fontSize: 15.0),
)
),
_TypeError (type 'Null' is not a subtype of type 'bool')
Sometimes data["success"]
has a response of null
but it usually is true
or false
boolean
.
I'm using the spacexdata.com api for launches: https://docs.spacexdata.com/#bc65ba60-decf-4289-bb04-4ca9df01b9c1 and it is not data I control.
Hoping someone can help
CodePudding user response:
Since this data?["success"] != null ?
is your way of checking success, you need to apply it further down, too:
Text(
data?["success"] != null ? "Success" : "Failure",
style: TextStyle(
color: data?["success"] != null ? Colors.green : Colors.red,
fontSize: 15.0),
)
),
Obviously, I have no clue if handling the data that way is "correct", but you should no longer get errors, your success is green and your failure is red.