先定义2种不同场景下的颜色(p.s.我这里用到暗黑主题,不需要的可以去掉)
class _DarkColors {
static final highlightColor = const Color(0x40CCCCCC);
static final splashColor = const Color(0x40CCCCCC);
}
class _LightColors {
static final highlightColor = const Color(0x66BCBCBC);
static final splashColor = const Color(0x66C8C8C8);
}
static final ThemeData themeDataLight = ThemeData(
//关键代码就这个:
//iOS不需要水波纹
highlightColor: Platform.isAndroid ? _LightColors.highlightColor : Colors.transparent,
splashColor: Platform.isAndroid ? _LightColors.splashColor : Colors.transparent,
);
static final ThemeData themeDataDark = ThemeData(
highlightColor: Platform.isAndroid ? _DarkColors.highlightColor : Colors.transparent,
splashColor: Platform.isAndroid ? _DarkColors.splashColor : Colors.transparent,
);
能看懂吧?对了,上面的颜色取值是从源码theme_data.dart
里复制过来的,各位可以放心使用。
网友评论