obscureString method
Obscures sensitive string data by showing only partial characters.
For strings with minLength+ characters: shows first 3 and last 2 characters.
For shorter strings: shows first and last character.
Single character strings are returned unchanged.
minLength defines the minimum length to apply the obscure logic (default: 5).
Implementation
String obscureString(String input, {int minLength = 5}) {
final int length = input.length;
if (length <= 1) return input;
if (length <= minLength) {
return input[0] + '*' * (length - 2) + input[length - 1];
}
// For strings longer than minLength, show the first 3 and last 2 characters
return "${input.substring(0, 3)}${'*' * (length - 5)}${input.substring(length - 2)}";
}