我連續有 3 個按鈕,如下所示:按鈕 1 按鈕 2 按鈕 3
,我只想要所選一個粗體的文本。例如:按鈕 1 按鈕 2 按鈕 3
最好和最簡單的方法是什么?
uj5u.com熱心網友回復:
創建一個變數來保存當前選中的按鈕。然后基于此,您可以像下面這樣切換 fontWeight
int selectedButton = 0;
Row(
children:List.generate(3, (index) {
return InkWell(
onTap:(){
setState((){selectedButton = index;});
},
child: Text("button $index", style: TextStyle(
fontWeight : selectedIndex == index ? FontWeight.w900: FontWeight.w400,
))
)
})
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/505345.html
下一篇:如何將結果從命令輸出到文本框