分享

如何在 Flutter 中禁用默认的 Widget 飞溅效果

 大前端之旅 2022-03-10

如何在 Flutter 中禁用默认的 Widget 飞溅效果

默认情况下,许多 Flutter Material Design 小部件在被选中时会显示飞溅效果。

这适用于IconButtonInkWellListTile和许多其他部件。

如果您正在创建一个完全自定义的设计并希望在整个应用程序范围内禁用此功能,您需要做的就是:

MaterialApp(
  theme: ThemeData(
    splashColor: Colors.transparent,
    highlightColor: Colors.transparent,
    hoverColor: Colors.transparent,
  ),
)

或者,您可以通过插入父Theme小部件将其应用于某个小部件子树:

Theme(
  data: Theme.of(context).copyWith(
    splashColor: Colors.transparent,
    highlightColor: Colors.transparent,
    hoverColor: Colors.transparent,
  )
  child: child,
)

您还可以直接为特定小部件禁用此功能:

IconButton(
  splashColor: Colors.transparent,
  highlightColor: Colors.transparent,
  hoverColor: Colors.transparent,
  icon: someIcon,
  onPressed: someCallback,
)

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章