我正在嘗試使用來自 API 的值,但此值在顯示之前需要進行一些更改。
這就是我收到價值的方式:
Name.MAGIC
我希望它像這樣顯示:
Magic
這是代碼
Text(
finalApi![widget.index].type.name.toString(),
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
有任何想法嗎?
uj5u.com熱心網友回復:
我們將使用這個函式:
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
在你的情況下使用這個:
Text(
extractName(finalApi![widget.index].type.name.toString()),
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/534460.html
標籤:扑应用程序接口
