StringX extension

Main extension on String providing comprehensive conversion and formatting tools.

on

Properties

blankToNull → String?

Available on String, provided by the StringX extension

Returns null if blank, otherwise this. Useful for form validation chains.
no setter
capitalize → String

Available on String, provided by the StringX extension

Capitalizes only the first character.
no setter
fromBase64OrNull → String?

Available on String, provided by the StringX extension

Decodes Base64 (standard or URL-safe) back to a UTF-8 string, returning null when the input is not valid Base64 text.
no setter
isAlphanumeric → bool

Available on String, provided by the StringX extension

Returns true if the string only contains letters and numbers.
no setter
isBlank → bool

Available on String, provided by the StringX extension

Returns true if the string is purely whitespace or empty.
no setter
isNotBlank → bool

Available on String, provided by the StringX extension

Returns true if the string contains non-whitespace characters.
no setter
jsonDecodeOrNull → dynamic

Available on String, provided by the StringX extension

Decodes JSON, returns null on failure instead of throwing.
no setter
lines → List<String>

Available on String, provided by the StringX extension

Lines split on \n, \r\n, or \r.
no setter
normalizeWhitespace → String

Available on String, provided by the StringX extension

Collapses internal whitespace runs to a single space and trims the ends.
no setter
readingTimeMinutes → int

Available on String, provided by the StringX extension

Estimates the reading time in minutes (225 words per minute).
no setter
removeWhitespace → String

Available on String, provided by the StringX extension

Removes all whitespace, including internal.
no setter
reversed → String

Available on String, provided by the StringX extension

Reverses the string (Unicode-safe via runes).
no setter
stripHtmlTags → String

Available on String, provided by the StringX extension

Removes anything that looks like an HTML/XML tag.
no setter
swapCase → String

Available on String, provided by the StringX extension

Swaps the case of every character.
no setter
toBase64 → String

Available on String, provided by the StringX extension

UTF-8 Base64 encoding of this string.
no setter
toBool → bool

Available on String, provided by the StringX extension

Parses string as boolean ('true' evaluates to true, else false).
no setter
toBoolOrNull → bool?

Available on String, provided by the StringX extension

Lenient boolean parsing. Returns null when the value is not recognizable as a boolean.
no setter
toCamelCase → String

Available on String, provided by the StringX extension

'Hello World' -> 'helloWorld'
no setter
toDotCase → String

Available on String, provided by the StringX extension

'hello world' -> 'hello.world'
no setter
toDoubleOrNull → double?

Available on String, provided by the StringX extension

Parses to double, returns null on failure.
no setter
toDoubleOrZero → double

Available on String, provided by the StringX extension

Parses to double, returns 0.0 on failure.
no setter
toDurationOrNull → Duration?

Available on String, provided by the StringX extension

Parses "SS", "MM:SS", or "HH:MM:SS" into a Duration, returns null on failure.
no setter
toIntOrNull → int?

Available on String, provided by the StringX extension

Parses to int, returns null on failure.
no setter
toIntOrZero → int

Available on String, provided by the StringX extension

Parses to int, returns 0 on failure.
no setter
toJsonMapOrNull → Map<String, dynamic>?

Available on String, provided by the StringX extension

Parses JSON and returns Map<String, dynamic> or null if invalid or not a Map.
no setter
toKebabCase → String

Available on String, provided by the StringX extension

'Hello World' / 'helloWorld' -> 'hello-world'
no setter
toPascalCase → String

Available on String, provided by the StringX extension

'hello world' -> 'HelloWorld'
no setter
toScreamingSnakeCase → String

Available on String, provided by the StringX extension

'hello world' -> 'HELLO_WORLD'
no setter
toSentenceCase → String

Available on String, provided by the StringX extension

Capitalizes only the first character.
no setter
toSlug → String

Available on String, provided by the StringX extension

URL-safe slug: lowercased, spaces->hyphens, non-alphanumeric stripped. 'Hello World! 2024' -> 'hello-world-2024'
no setter
toSnakeCase → String

Available on String, provided by the StringX extension

'Hello World' / 'helloWorld' -> 'hello_world'
no setter
toTitleCase → String

Available on String, provided by the StringX extension

Capitalizes the first letter of each whitespace-delimited word.
no setter
toUriOrNull → Uri?

Available on String, provided by the StringX extension

Parses string to Uri, returns null on failure.
no setter
words → List<String>

Available on String, provided by the StringX extension

Words split on whitespace, underscores, hyphens, and camelCase boundaries — the same tokenizer the case converters use.
no setter

Methods

charAtOrNull(int index) → String?

Available on String, provided by the StringX extension

The character at index, or null when out of range.
chunked(int size) → List<String>

Available on String, provided by the StringX extension

Splits into consecutive pieces of at most size characters.
countOccurrences(String pattern) → int

Available on String, provided by the StringX extension

Counts non-overlapping occurrences of pattern.
endsWithIgnoreCase(String other) → bool

Available on String, provided by the StringX extension

Case-insensitive String.endsWith.
ensurePrefix(String prefix) → String

Available on String, provided by the StringX extension

Prepends prefix unless it is already there.
ensureSuffix(String suffix) → String

Available on String, provided by the StringX extension

Appends suffix unless it is already there.
equalsIgnoreCase(String other) → bool

Available on String, provided by the StringX extension

Case-insensitive equality.
hasLengthBetween(int min, int max) → bool

Available on String, provided by the StringX extension

Passes if length falls within [min, max] after trimming.
indent(int spaces, {String? prefix}) → String

Available on String, provided by the StringX extension

Prefixes every line with spaces spaces (or a custom prefix).
initials({int max = 2}) → String

Available on String, provided by the StringX extension

Up to max uppercase initials taken from the leading words.
levenshteinDistance(String other) → int

Available on String, provided by the StringX extension

Levenshtein edit distance to other.
mask({int unmaskedStart = 0, int unmaskedEnd = 0, String maskChar = '*'}) → String

Available on String, provided by the StringX extension

Masks characters with maskChar, preserving unmaskedStart characters at the beginning and unmaskedEnd characters at the end.
padCenter(int width, [String padChar = ' ']) → String

Available on String, provided by the StringX extension

Pads both sides so the result is width characters wide.
removePrefix(String prefix) → String

Available on String, provided by the StringX extension

Removes prefix if present at the start of this string.
removeSuffix(String suffix) → String

Available on String, provided by the StringX extension

Removes suffix if present at the end of this string.
repeat(int count) → String

Available on String, provided by the StringX extension

Repeats this string count times.
similarityTo(String other) → double

Available on String, provided by the StringX extension

Similarity to other in [0, 1], derived from levenshteinDistance.
startsWithIgnoreCase(String other) → bool

Available on String, provided by the StringX extension

Case-insensitive String.startsWith.
substringSafe(int start, [int? end]) → String

Available on String, provided by the StringX extension

String.substring that clamps out-of-range bounds instead of throwing.
toDuration() → Duration

Available on String, provided by the StringX extension

Parses "SS", "MM:SS", or "HH:MM:SS" into a Duration.
trimHyphens() → String

Available on String, provided by the StringX extension

Removes leading and trailing hyphens.
truncate(int maxLength, {String ellipsis = '...'}) → String

Available on String, provided by the StringX extension

Truncates to maxLength chars, appending ellipsis if cut.
truncateWords(int maxLength, {String ellipsis = '...'}) → String

Available on String, provided by the StringX extension

Truncates at a word boundary instead of mid-word.
wrap(String prefix, [String? suffix]) → String

Available on String, provided by the StringX extension

Wraps the string with prefix and suffix (defaults to prefix).