StringExtensions extension

Extension methods on String providing common text utilities absent from the Dart SDK.

final text = '  hello world  ';
print(text.isBlank);       // false
print(text.toTitleCase()); // "Hello World"
print(text.toSnakeCase()); // "hello_world"
on

Properties

isBlank bool

Available on String, provided by the StringExtensions extension

Whether this string is empty or consists solely of whitespace characters.
no setter
isNotBlank bool

Available on String, provided by the StringExtensions extension

Whether this string contains at least one non-whitespace character.
no setter

Methods

capitalize() String

Available on String, provided by the StringExtensions extension

Returns a copy of this string with the first character uppercased.
decapitalize() String

Available on String, provided by the StringExtensions extension

Returns a copy of this string with the first character lowercased.
orNull() String?

Available on String, provided by the StringExtensions extension

Returns null if this string isBlank, otherwise returns the string itself. Useful for converting blank strings to null in forms.
removeDiacritics() String

Available on String, provided by the StringExtensions extension

Returns a copy of this string with common diacritical marks removed.
toCamelCase() String

Available on String, provided by the StringExtensions extension

Converts this string to camelCase.
toKebabCase() String

Available on String, provided by the StringExtensions extension

Converts this string to kebab-case.
toPascalCase() String

Available on String, provided by the StringExtensions extension

Converts this string to PascalCase.
toSnakeCase() String

Available on String, provided by the StringExtensions extension

Converts this string to snake_case.
toTitleCase() String

Available on String, provided by the StringExtensions extension

Converts this string to Title Case.
truncate(int maxLength, {String suffix = '…'}) String

Available on String, provided by the StringExtensions extension

Truncates this string to at most maxLength characters.