0

I'm 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's the code

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

Any ideas?

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
yuuu
  • 21
  • 4

1 Answers1

0

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,
     ),
  ),
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Gwhyyy
  • 7,554
  • 3
  • 8
  • 35