circleContainerWithText function
Implementation
Widget circleContainerWithText(String name) {
// Extract the first letter of the first part of the name
String firstLetter = name.isNotEmpty ? name.substring(0, 1) : "";
// Check if the name contains a space and extract the first letter of the second part
String secondLetter = "";
if (name.contains(" ")) {
int spaceIndex = name.indexOf(" ");
if (spaceIndex + 1 < name.length) {
secondLetter = name.substring(spaceIndex + 1, spaceIndex + 2);
}
}
// Concatenate the two letters
String displayText;
if(secondLetter != ""){
displayText = "$firstLetter$secondLetter";
}else{
displayText = firstLetter;
}
// Generate a random color
Color backgroundColor = Colors.primaries[Random().nextInt(Colors.primaries.length)];
// Create a circular container with the concatenated letters in the middle
return Container(
width: 26,
height: 26,
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.4),
shape: BoxShape.circle,
),
child: Center(
child: Text(
displayText.toUpperCase(),
style: const TextStyle(
color: Colors.white,
fontSize: 10,
),
),
),
);
}