我有以下列表图块
Container buildContactTile(BuildContext context, Color backgroundColor, Color foregroundColor, UserModel contact,
ContactListController controller) {
final ThemeData theme = Theme.of(context);
return Container(
decoration: BoxDecoration(color: backgroundColor, borderRadius: const BorderRadius.all(Radius.circular(5.0))),
child: ListTile(
leading: ProfileAvatar(
backgroundColor: foregroundColor,
photoURL: contact.photoURL,
radius: 15.0,
fallback: ProfileAvatar.nameAvatar(displayName: contact.displayName),
),
title: Text(contact.displayName, style: theme.textTheme.bodyText1.apply(color: foregroundColor)),
trailing: _interactive ? Icon(Icons.add, color: foregroundColor) : null,
onTap: () => _interactive ? controller.updateSelectedContacts(contact) : null,
),
);
}
然后用容器包装它,以根据小部件的状态为其提供不同的背景颜色。但是发生的是我的启动画面没有考虑圆形边界半径,因此启动画面颜色最终出现在列表图块的角上。如何使飞溅的颜色透明或解决圆角?按住ListTile时,您会在角落看到以下内容
最佳答案
将整个Container
包装在Theme
中,然后将ThemeData
的splashColor
和highlightColor
设置为Colors.transparent
。
引用How to disable default Widget splash effect in Flutter?
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Theme(
data: ThemeData(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
child: Container(
decoration: BoxDecoration(
color: Colors.blueGrey,
borderRadius: const BorderRadius.all(Radius.circular(15.0)),
),
child: ListTile(
leading: const Icon(Icons.flight_land),
title: const Text("Trix's airplane"),
subtitle: const Text('The airplane is only in Act II.'),
enabled: true,
onTap: () {
print('Something');
},
),
),
);
}
}
关于flutter - 有没有办法从我的列表图 block 中删除启动画面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62639773/