extension Extension on Object { bool isNullOrEmpty() => this == null || this == ''; bool isNullEmptyOrFalse() => this == null || this == '' || !this; bool isNullEmptyZeroOrFalse() => this == null || this == '' || !this || this == 0; } /// truncate the [String] without cutting words. The length is calculated with the suffix. extension Truncate on String { String truncate(int max, {String suffix = ''}) { try { return length <= max ? this : '${substring(0, max - suffix.length)}$suffix'; } catch (e) { return this; } } }