flutter InkWell小部件在容器内无法工作

szqfcxe2  于 2023-08-07  发布在  Flutter
关注(0)|答案(1)|浏览(155)

我试图将InkWell Widget添加到我在Flutter中制作的定制卡中,但它似乎不起作用,无论我做什么,或者我将它放在代码中的位置。cardAction是一个打开URL链接的函数
这里是代码

@override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Transform(
      transform: Matrix4.translationValues(0, -screenSize.height / 20, 0),
      child: Container(
        margin: EdgeInsets.symmetric(
          vertical: screenSize.height / 4,
          horizontal: screenSize.width / 8,
        ),
        child: Container(
          margin: EdgeInsets.only(bottom: screenSize.height / 20),
          decoration: BoxDecoration(
            color: Colors.amber[50],
            borderRadius: BorderRadius.circular(screenSize.width / 10),
            boxShadow: [
              BoxShadow(
                color: Colors.black.withOpacity(0.3),
                offset: const Offset(0, 6),
                blurRadius: screenSize.width / 50,
              )
            ],
          ),
          child: AspectRatio(
            aspectRatio: (screenSize.height / 5) / (screenSize.width / 9),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(screenSize.width / 10),
              child: InkWell(
                onTap: () async {
                  cardAction;
                },
                child: BuildParallaxBackground(
                  context: context,
                  assetName: cardAsset,
                  imageKey: _backgroundImageKey,
                  title: cardTitle,
                  gradient: gradient,
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

字符串
这里是parallaxBackground代码,如果它很重要...

@override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Flow(
          delegate: ParallaxFlowDelegate(
            scrollable: Scrollable.of(context),
            listItemContext: context,
            backgroundImageKey: imageKey,
          ),
          children: [
            Image.asset(
              assetName,
              fit: BoxFit.cover,
              key: imageKey,
            )
          ],
        ),
        if (gradient == true) ...[
          _buildGradient(),
        ],
        if (title != '') ...[
          _buildTitle(),
        ],
      ],
    );
  }


我试着把它到处都放,但它不起作用

mzsu5hc0

mzsu5hc01#

用材质包裹你的InkWell并将颜色设置为透明

child: ClipRRect(
      borderRadius: BorderRadius.circular(screenSize.width / 10),
      child: Material(
        color: Colors.transparent,
        child: InkWell(
          onTap: ...
          child: ...
        ),
      ),
    ),

字符串

相关问题