nullToDef static method

String nullToDef(
  1. String? value,
  2. String def, {
  3. String? suffix,
  4. bool defSuffix = false,
})

如果为空返回默认值def, defSuffix为true时拼接上后缀 suffix if it is empty, return the default value def, and if defSuffix is true, append the suffix suffix

Implementation

static String nullToDef(String? value, String def, {String? suffix, bool defSuffix = false}) {
  final buffer = StringBuffer();
  if (isEmpty(value)) {
    buffer.write(def);
    if (defSuffix) {
      buffer.write(suffix ?? '');
    }
    return buffer.toString();
  }
  buffer.write(value);
  buffer.write(suffix ?? '');
  return buffer.toString();
}