Flutter Stack Clip 未检测到手势

Flutter Stack Clip not detecting gestures

我正在尝试制作一款纸牌游戏,并在前一款游戏中构建纸牌。但是堆栈剪辑参数给我的工作比我想象的要多。

如果我在参数中什么都不放,输出是这样的:

如果我输入 clipBehavior: Clip.none, 视觉输出是这样的 (没有红线):

太棒了!这就是我想要的视觉效果。唯一的问题是,当我在第一个图像边界(由红线表示)之外触摸时,抖动不会渲染触摸。

有谁知道如何使手势检测再次工作?

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Stack Test',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter Stack Test'),
      ),
      body: const Center(
        child: TestStackWidget(
          listSize: 3,
          width: 200,
        ),
      ),
    );
  }
}

class TestStackWidget extends StatelessWidget {
  const TestStackWidget({
    Key? key,
    required this.width,
    required this.listSize,
  }) : super(key: key);

  final double width;
  final int listSize;

  @override
  Widget build(BuildContext context) {
    return Stack(
      clipBehavior: Clip.none,  // ----------------------------Here-----------------------
      children: [
        SizedBox(
          width: width,
          child: AspectRatio(
            aspectRatio: 1 / 1.61,
            child: Card(
              margin: EdgeInsets.zero,
              color: Colors.blue,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(20),
              ),
              child: InkWell(
                onTap: () => debugPrint(listSize.toString()),
                borderRadius: BorderRadius.circular(20),
                child: Container(
                  decoration: BoxDecoration(
                    border: Border.all(),
                    borderRadius: BorderRadius.circular(20),
                  ),
                ),
              ),
            ),
          ),
        ),
        if (listSize > 0)
          Positioned(
            top: 50,
            left: 20,
            child: TestStackWidget(
              width: width,
              listSize: listSize - 1,
            ),
          ),
      ],
    );
  }
}

我发现 this issue 关于这个问题,我找到的唯一简单的解决方案是将第一个 child 包装在 Stack 中的 Column 中,然后添加一个 SizedBox 像这样:

Column(
mainAxisSize: MainAxisSize.min,
children: [
  SizedBox(
    width: width,
    child: AspectRatio(
      aspectRatio: 1 / 1.61,
      child: Card(
        margin: EdgeInsets.zero,
        color: Colors.blue,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(20),
        ),
        child: InkWell(
          onTap: () => debugPrint(listSize.toString()),
          borderRadius: BorderRadius.circular(20),
          child: Container(
            decoration: BoxDecoration(
              border: Border.all(),
              borderRadius: BorderRadius.circular(20),
            ),
          ),
        ),
      ),
    ),
  ),
  SizedBox(height: 50.0 * listSize), //--------------Added-------------------
],