When a field comes back null from the API and you display it with Text(state.field.toString()), user will see the word "null" sitting there on the screen. For them this means nothing.
Or the backend serializes null as the literal string "null". Same thing.
Or the field is an empty string, then there will be a blank spot where a value should be. Looks just as broken.
Text(state.field ?? '-') seems to handle these, but it misses some cases.
This extension handles all:
extension StringX on String? { bool get isUsable { return this != null && this!.isNotEmpty && this != 'null'; } String orPlaceholder([String placeholder = '-']) { if (!isUsable) return placeholder; return this!; }}
If objects in the chain can be null, wrap the whole expression in parentheses. orPlaceholder() runs on the result of the whole chain, even if something in the middle is null: