添加Material风格的水波纹

添加点按涟漪效果 (Material Design)

实用教程chevron_right手势操作 (Gestures)chevron_right添加点按涟漪效果 (Material Design)

当我们在开发遵循 Material Design 规范应用的时候,我们可能会需要为某个 widgets 的点击加入涟漪效果。

Flutter 提供了 InkWell widget 来实现这个功能。你可以通过以下步骤实现涟漪效果:

  1. 创建一个想要点击的 widget;
  2. InkWell widget 包裹它,并设置回调函数,就可以显示涟漪动画了。

dart

// The InkWell wraps the custom flat button widget.
InkWell(
  // When the user taps the button, show a snackbar.
  onTap: () {
    ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
      content: Text('Tap'),
    ));
  },
  child: const Padding(
    padding: EdgeInsets.all(12),
    child: Text('Flat Button'),
  ),
)

content_copy

交互式样例

#

posted on 2024-12-10 09:29  AtlasLapetos  阅读(11)  评论(0)    收藏  举报