I'm trying to get the first word but I can't seem to find a way. I've tried using split like so:
Text("${contactList[index].userName!.split(" ")}, ")
But the result is an array like so:
[aufa, taf]
Any solutions?
CodePudding user response:
according to the results you should write:
Text("${contactList[index].userName!.split(" ")[0]}, ")
instead of :
Text("${contactList[index].userName!.split(" ")}, ")
CodePudding user response:
Try below code hope its help to you.
Text("${contactList[index].userName!.split(" ").elementAt(0)"),
Simple Example:
void main() {
String sampleText = "aufa taf";
var first = sampleText.split(" ").elementAt(0); // aufa
var second = sampleText.split(" ").elementAt(1);//taf
print(first);
}
CodePudding user response:
Try this:
Text(
"${contactList[index].userName!.split(" ")[0]}, ",
),