堆叠中负 Y 偏移的印刷机抖动问题

Meh*_*met 5 flutter

我在堆栈中有两个小部件。下面将对此进行演示。

导航栏

第二个小部件是一个按钮,它位于具有负 Y 轴的定位小部件中。

问题是溢出了,无法点击。我有什么办法可以解决这个问题吗?

Stack(
    fit: StackFit.expand,
    overflow: Overflow.visible,
    clipBehavior: Clip.none,
    alignment: AlignmentDirectional.topCenter,
    children: [
      ClipRRect(
        borderRadius: BorderRadius.all(Radius.circular(29)),
        child: ClipPath(
          clipper: NavbarClipper(),
          child: Container(
            color: Colors.white,
          ),
        ),
      ),
      Positioned(
        top: -30,
        child: Container(
          width: context.dynamicHeight(0.16),
          height: context.dynamicWidth(0.16),
          child: FittedBox(
            child: FloatingActionButton(
              onPressed: () {},
              backgroundColor: Colors.orange,
              child: Icon(Icons.ac_unit),
            ),
          ),
        ),
      )
    ],
  )
Run Code Online (Sandbox Code Playgroud)

谢谢。

小智 1

您可以用 padding 包裹矩形,而不是按钮的负边距

class MyHomePage extends StatefulWidget {
  MyHomePage();

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Color color = Colors.orange;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: 200,
        padding: EdgeInsets.all(32),
        child: Stack(
          fit: StackFit.expand,
          clipBehavior: Clip.none,
          alignment: AlignmentDirectional.topCenter,
          children: [
            Padding(
              padding: EdgeInsets.only(top: 30),
              child: ClipRRect(
                borderRadius: BorderRadius.all(Radius.circular(20)),
                child: ClipRRect(
                  child: Container(
                    color: Colors.blue,
                  )
                ),
              ),
            ),
            Positioned(
              top: 0,
              child: Container(
                width: 50,
                height: 50,
                child: FittedBox(
                  child: FloatingActionButton(
                    onPressed: () {
                      setState((){
                        color = (color == Colors.red) ? Colors.orange : Colors.red;
                      });
                    },
                    backgroundColor: color,
                    child: Icon(Icons.ac_unit),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)