flutter 如何单击卡在底层的堆栈项目?

biswetbf  于 2022-11-30  发布在  Flutter
关注(0)|答案(1)|浏览(129)

下面是我代码的一个简单视图。它有两个堆栈元素,都包含可点击的内容。顶部元素覆盖了底部元素,我不能点击底部元素。我该怎么办?
`

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: SafeArea(
      child: Container(
       ///decoration
        height: SizeConfig.screenHeight,
        width: SizeConfig.screenWidth,
        child: Stack(
          children: [
            Container(
              width: SizeConfig.screenWidth,
              height: SizeConfig.screenHeight! * 0.3,
              ///decoration
              ///child: content
              ///THIS IS FIXED CONTENT. LIKE AN 'HEADER'
              ///clickable contents here
            ),
            SingleChildScrollView(
              child: Container(
                margin: EdgeInsets.only(top: SizeConfig.screenHeight! * 0.25),
                constraints: BoxConstraints(
                  minHeight: SizeConfig.screenHeight! * 0.75,
                  maxHeight: double.infinity,
                ),
                ///decoration and child, content
                ///THIS IS CONTENT SIDE FOR PAGE.
                ///this is scrollable and when scrolling up it goes above the header, continues up
                ///looks like DraggableScrollableSheet
                //////clickable contents here
              ),
            )
          ],
        ),
      ),
    ),
  );
}

`
我尝试了忽略指针、吸收指针等,但无法解决。
这是我下面的解决方案。它的背景为flexibleSpace的CustomScrollView应用程序栏。

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          //color: HTKColors.the_green_color,
          ///decoration
          height: SizeConfig.screenHeight,
          width: SizeConfig.screenWidth,
          child: Stack(
            children: [
              Container(
                width: SizeConfig.screenWidth,
                height: SizeConfig.screenHeight! * 0.3,
                ///decoration
              ),
              CustomScrollView(
                slivers: [
                  SliverAppBar(
                    expandedHeight: SizeConfig.screenHeight! * 0.25,
                    backgroundColor: Colors.transparent,
                    leading: const SizedBox(),
                    flexibleSpace: FlexibleSpaceBar(
                      collapseMode: CollapseMode.none,
                      background: SizedBox(
                        width: SizeConfig.screenWidth,
                        height: SizeConfig.screenHeight! * 0.25,
                        ///my bottom element (header)
                      ),
                    ),
                  ),
                  SliverList(
                    delegate: SliverChildListDelegate([
                      Container(
                        constraints: BoxConstraints(
                          minHeight: SizeConfig.screenHeight! * 0.75,
                          maxHeight: double.infinity,
                        ),
                        ///draggable top element
                      ),
                    ]),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
n6lpvg4x

n6lpvg4x1#

这正是我想要的:
绿色区域可以达到无限长,可以滚动。当我向上滚动应该可以到红色区域以上。如果我没有滚动绿色区域,我可以看到红色区域;我应该可以单击红色区域中的元素。
示例代码如下:

Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Stack(
          children: [
            Column(
              children: [
                Container(
                  width: SizeConfig.screenWidth,
                  height: SizeConfig.screenHeight! * 0.25,
                  color: Colors.red,
                  ///clickable elements here
                ),
                Container(
                  width: SizeConfig.screenWidth,
                  height: SizeConfig.screenHeight! * 0.75,
                  color: Colors.transparent
                ),
              ],
            ),
            SingleChildScrollView(
              child: Column(
                children: [
                  Container(
                    width: SizeConfig.screenWidth,
                    height: SizeConfig.screenHeight! * 0.25,
                    color: Colors.transparent,
                  ),
                  Container(
                      width: SizeConfig.screenWidth,
                      constraints: BoxConstraints(
                        minHeight: SizeConfig.screenHeight! * 0.75,
                        maxHeight: double.infinity,
                      ),
                      ///this elemend can be infinitely long by content
                      color: Colors.green
                      ///clickable elements here
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

@eamirho3英寸

相关问题