简体   繁体   English

颤动:Inkwell 在堆栈小部件中不起作用

[英]flutter :Inkwell not working in stack widget

I created a stack viewpager by this reference :通过这个参考创建了一个堆栈查看器:

  body: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      
      Stack(
      children: [
        Positioned.fill(
          child: Align(
            alignment: Alignment.centerLeft,
            child: SizedBox(
              width: _itemWidth,
              child: FractionallySizedBox(
              child: InkWell(
                onTap: () => debugPrint("clicked"), ///this part not works
                child: PageViewItem(
                  index: _firstItemIndex,
                  width: _itemWidth,
                  url: model[_firstItemIndex],
                  ),
                ),
              ),
            ),
          ),
        ),
        SizedBox(
          height: 250,
          child: PageView.builder(
            padEnds: false,
            controller: _controller,
            itemBuilder: (context, index) {
              return Opacity(
                opacity: index <= _firstItemIndex ? 0 : 1,
                child: PageViewItem(
                  index: index,

                  width: _itemWidth,
                  url: model[index],

                ),
              );
            },
            itemCount: model.length,
          ),
        ),
      ],
),
    ],

in this part :在这部分:

 InkWell(
    onTap: () => debugPrint("clicked"), ///this part not works
    child: PageViewItem(
      index: _firstItemIndex,
      width: _itemWidth,
      url: model[_firstItemIndex],
      ),
    ),

onTap Not working because is under PageView.builder . onTap 不工作,因为在PageView.builder下。 do you have any idea to fix this issue?你有什么想法来解决这个问题吗?

That's because top widget in the stack, stack works as a layers, the last child in the children list will be the greatest zIndex one, so any widget below it is not accessible, you need to bring it to front to activate the click, swap the children and making the InkWell 's positioned Widget the last child in the children will solve your issue这是因为栈顶的部件,栈作为一个层, children列表中的最后一个孩子将是最大的zIndex一个,所以它下面的任何部件都无法访问,你需要bring it to front来激活点击,交换孩子们并将InkWell的定位小部件设置为孩子们中的最后一个孩子将解决您的问题

Stack(
  children: [
    SizedBox(
      height: 250,
      child: PageView.builder(
        padEnds: false,
        controller: _controller,
        itemBuilder: (context, index) {
          return Opacity(
            opacity: index <= _firstItemIndex ? 0 : 1,
            child: PageViewItem(
              index: index,

              width: _itemWidth,
              url: model[index],

            ),
          );
        },
        itemCount: model.length,
      ),
    ),
    Positioned.fill(
      child: Align(
        alignment: Alignment.centerLeft,
        child: SizedBox(
          width: _itemWidth,
          child: FractionallySizedBox(
          child: InkWell(
            onTap: () => debugPrint("clicked"), ///this part not works
            child: PageViewItem(
              index: _firstItemIndex,
              width: _itemWidth,
              url: model[_firstItemIndex],
              ),
            ),
          ),
        ),
      ),
    ),
  ],
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM