Bug fixes

This commit is contained in:
Abdullah Alassaf
2024-06-30 15:10:01 +03:00
parent 9b37545691
commit 288ea6a1e2
8 changed files with 112 additions and 97 deletions

View File

@ -63,9 +63,16 @@ class StringHelpers {
}
static String toTitleCase(String text) {
return text
.split(' ')
.map((word) => word[0].toUpperCase() + word.substring(1))
.join(' ');
if (text.contains(' ')) {
//remove empty elements
String title = text.split(' ').where((element) => element.isNotEmpty).join(' ');
String result = title
.split(' ')
.map((element) => element[0].toUpperCase() + element.substring(1))
.join(' ');
return result;
} else {
return text.toUpperCase();
}
}
}