Home > Back-end >  Flutter - How to format a Api text
Flutter - How to format a Api text

Time:11-15

im trying to use a value from a Api, but this value need some changes before show. This is how i receive the value

Name.MAGIC

and i want it to show like this

Magic

here is my code

Text(
  finalApi![widget.index].type.name.toString(),
  style: TextStyle(
    color: Colors.white,
    fontWeight: FontWeight.bold,
    fontSize: 15,
     ),
  ),

If anyone has any ideas of what i should do i would appreciate it!

CodePudding user response:

we will use this function:

String extractName(String text) {
List words = text.split(".");
String result = words.last.substring(0, 1).toUpperCase()   words.last.substring(1).toLowerCase();
return result ;
 }
print(extractName("Name.magic")); // Magic

in your case use this:

    Text(
  extractName(finalApi![widget.index].type.name.toString()),
  style: TextStyle(
    color: Colors.white,
    fontWeight: FontWeight.bold,
    fontSize: 15,
     ),
  ),
  • Related