InkWell 在某些地方使用某种方式嵌套widget时会导致水波纹效果失效.
也查阅过其他文章,这里总结一下最实用的,能够解决绝大部分常见场景下的失效问题,上代码;
Material(
child: Ink(
child: InkWell(
onTap: onTap,
child: Container(
child:Text("在此处包裹你的组件") ,///Wrap your components here
),
),
),
),
当然,这只是最简单的包裹组件的操作,需要详细使用,可参考源码:
///源码注释使用样例
/// Material(
/// color: Colors.grey[800],
/// child: Center(
/// child: Ink.image(
/// image: const AssetImage('cat.jpeg'),
/// fit: BoxFit.cover,
/// width: 300.0,
/// height: 200.0,
/// child: InkWell(
/// onTap: () { /* ... */ },
/// child: const Align(
/// alignment: Alignment.topLeft,
/// child: Padding(
/// padding: EdgeInsets.all(10.0),
/// child: Text(
/// 'KITTEN',
/// style: TextStyle(
/// fontWeight: FontWeight.w900,
/// color: Colors.white,
/// ),
/// ),
/// ),
/// )
/// ),
/// ),
/// ),
/// )