我在我的 flutter 应用程序中使用 GoogleFonts api,但现在我将每个文本的 fontStyle 手动设置为 GoogleFonts.roberto,但我想在 main.dart 的 ThemeData 中将其设置为默认值。但是 fontFamily: GoogleFonts.roberto 抛出一个错误,指出需要一个字符串值,那么我该如何实现呢?
我想在单击图块时更改 ListTile 文本的颜色,我该怎么做,而且颜色也应该只更改特定选定图块的颜色。我的方法如下:
ListView.builder(
itemCount: _antigen.plantAntigens.length,
itemBuilder: (BuildContext cntxt, int index) {
return ListTile(
title: Text(
_antigen.plantAntigens[index],
style: TextStyle(
color: controller.isSelected ? Colors.red : Colors.black87),
),
onTap: () {
controller.toogle();
});
},
),
Run Code Online (Sandbox Code Playgroud)
控制器的代码如下:
bool isSelected = false.obs;
toogle() {
isSelected = !isSelected;
}
Run Code Online (Sandbox Code Playgroud)