Reputation: 1347
When I try to display the parsed JSON data in ListView, I am receiving this error:
'package:flutter/src/widgets/text.dart': Failed assertion: line 213 pos 15: 'data != null': is not true.
I checked the parsed data, and some fields are null. What is the proper way to check if the data is null and instead display string "Empty" ?
Results getShipment(int index) {
return new Results(
cargoTrackerCode: data[index]["cargoTrackerCode"]
)
}
new Padding(
child: new Text(widget.results.customerName,
style: new TextStyle(
fontSize: 18.0,
color: Colors.white,
)
),
),
Upvotes: 0
Views: 5603
Reputation: 40423
You can use a ternary operator to do an inline if-else sort of statement.
data == null ? 'Empty' : data[index]["cargoTrackerCode"]
Upvotes: 6