当我按下它时,我有一张卡片列表,他的颜色发生了变化。在我将深色主题模式添加到我的应用程序之前它运行良好,当我按下它时它不会改变他的颜色
我的旧代码:
Widget build(BuildContext context) {
Color _colorContainer = Colors.white;
return DelayedDisplay(
delay: Duration(seconds: 2),
child:
InkWell(
onTap: () {
setState(() {
_colorContainer = _colorContainer == Colors.white ? Colors.yellow : Colors.white;
});
},
child: Card(
color: _colorContainer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
elevation: 4,
margin: EdgeInsets.symmetric(horizontal: 0.04.sw, vertical: 0.015.sh),
child: Text('Some Widgets')
),
),
);}
添加深色主题后的我的新代码相同但更改以下内容:
Color _colorContainer = Theme.of(context).cardColor;
和
setState(() {
_colorContainer = _colorContainer == Theme.of(context).cardColor ?Colors.yellow :
Theme.of(context).cardColor;
});
},
我的主题文件:
class MyThemes{
static final darkTheme = ThemeData(
scaffoldBackgroundColor: Colors.grey.shade900,
fontFamily: 'Amiri',
cardColor: Color(0xFF424242),
colorScheme: ColorScheme.dark(),
primaryColor: Colors.white,
appBarTheme: AppBarTheme(
backgroundColor: Colors.grey,
centerTitle: true,
titleTextStyle: TextStyle(fontWeight: FontWeight.bold),
),
);
static final lightTheme = ThemeData(
scaffoldBackgroundColor: Colors.white,
fontFamily: 'Amiri',
cardColor: Colors.white,
colorScheme: ColorScheme.light(),
primaryColor: Colors.black,
appBarTheme: AppBarTheme(
backgroundColor: Colors.pink,
centerTitle: true,
titleTextStyle: TextStyle(fontWeight: FontWeight.bold)
),
);
}