当 child 是 Chip Widget 时,Flutter MouseRegion 不工作

Flutter MouseRegion is not working when the child is a Chip Widget

当 child 是 Chip 小部件时,我的 flutter web 程序中的鼠标光标在悬停时不会变为单击光标。我将 Chip 更改为 Text 和 Container 小部件,并且鼠标光标更改没有任何问题。

下面是鼠标区域的代码。

return MouseRegion(
  cursor: SystemMouseCursors.click,
  child: Container(
    width: 200,
    alignment: Alignment.centerRight,
    child: GestureDetector(
      onTap: () {},
      child: Chip(
        backgroundColor: kLightPrimary,
        avatar: const Icon(
           Feather.phone_call,
           size: 18.0,
           color: kPrimaryColor,
        ),
        label: Text(
          "Test num",
          style: GoogleFonts.poppins(
              fontWeight: FontWeight.w500, color: kPrimaryColor),
          textAlign: TextAlign.end,
        ),
        padding: const EdgeInsets.all(kDefaultPadding),
      ),
    ),
  ),
),

将您的 GestureDetector 更改为 InkWell 这对我有用。

return  Container(
    width: 200,
    alignment: Alignment.centerRight,
    child: InkWell( //use InkWell insted of GestureDetector 
      onTap: () {},
      child: Chip(
        backgroundColor: kLightPrimary,
        avatar: const Icon(
           Feather.phone_call,
           size: 18.0,
           color: kPrimaryColor,
        ),
        label: Text(
          "Test num",
          style: GoogleFonts.poppins(
              fontWeight: FontWeight.w500, color: kPrimaryColor),
          textAlign: TextAlign.end,
        ),
        padding: const EdgeInsets.all(kDefaultPadding),
      ),
    ),
),

您希望在 Chip 上使用 MouseRegionGestureDetector,而不是 ActionChip

    ActionChip(
        onPressed() {/* use onPressed even if it would be empty */}
        backgroundColor: kLightPrimary,
        avatar: const Icon(
           Feather.phone_call,
           size: 18.0,
           color: kPrimaryColor,
        ),
        label: Text(
          "Test num",
          style: GoogleFonts.poppins(
              fontWeight: FontWeight.w500, color: kPrimaryColor),
          textAlign: TextAlign.end,
        ),
        padding: const EdgeInsets.all(kDefaultPadding),
      )