flutter 在手势检测器或inwell中环绕点击时,TabBar不工作

qxsslcnc  于 2022-11-17  发布在  Flutter
关注(0)|答案(2)|浏览(175)

我需要调用一个函数,当一个标签在标签栏中被按下,但标签不再reac,即使有墨水池。我还 Package 了位置的标签部件本身在一个手势检测器或墨水池,我做错了什么?

TabBar(
        indicatorColor: Colors.white,
        tabs: [
        GestureDetector(//That does not work even with an InWell
          onTap: ()async{
            await _dbLogin.function();
          },
          child:  Stack(
        children: [
          Positioned(
          left: 40,
          child: const Tab(icon: Icon(Icons.person_outline,color: Colors.lightGreen,size: 30,))
          ),
          currentUser?.priceAlert==true?
          Positioned(
            bottom: 20,
            left: 40,
            child: const CircleAvatar(
              radius: 4.0,
              backgroundColor: Colors.red,
            ),
          ):Container() 
        ],
        ),
        ),
        Stack(
          children: [
            Positioned(
              left: 40,
              child: const Tab(icon: Icon(Icons.people_alt_outlined,color: Colors.lightGreen,size: 30,)),
            ),
            currentUser?.productAlert==true?Positioned(
              bottom: 20,
               left: 40,
              child: const CircleAvatar(
                radius: 4.0,
                backgroundColor: Colors.red,
              ),
            ):Container() 
          ],
        ),
        Stack(
          children: [
            Positioned(
              left: 40,
              child: Tab(icon: currentUser?.profilVerified==true?const Icon(Icons.account_circle_outlined,color:Colors.lightGreen,size: 30,):const Icon(Icons.account_circle_outlined,color:Colors.red,size: 30,))
            )
          ],
        )
        ],
      ),

有什么主意吗?谢谢

0qx6xfy6

0qx6xfy61#

TabBar有内置的功能,可以在按下制表符时执行操作。

onTap: (index) {
    //do what you want here
  },

其中index是按下的制表符的索引

1wnzp6jl

1wnzp6jl2#

艾沃是对的,我只是让它更具体地为你表达你的愿望:

TabBar(
      indicatorColor: Colors.white,
      onTap: (index) async {
        if (index == 0) {
          await _dbLogin.function();
        }
      },
      tabs: [
        Stack(
          children: [
            Positioned(
                left: 40,
                child: const Tab(
                    icon: Icon(
                  Icons.person_outline,
                  color: Colors.lightGreen,
                  size: 30,
                ))),
            currentUser?.priceAlert == true
                ? Positioned(
                    bottom: 20,
                    left: 40,
                    child: const CircleAvatar(
                      radius: 4.0,
                      backgroundColor: Colors.red,
                    ),
                  )
                : Container()
          ],
        ),
        Stack(
          children: [
            Positioned(
              left: 40,
              child: const Tab(
                  icon: Icon(
                Icons.people_alt_outlined,
                color: Colors.lightGreen,
                size: 30,
              )),
            ),
            currentUser?.productAlert == true
                ? Positioned(
                    bottom: 20,
                    left: 40,
                    child: const CircleAvatar(
                      radius: 4.0,
                      backgroundColor: Colors.red,
                    ),
                  )
                : Container()
          ],
        ),
        Stack(
          children: [
            Positioned(
                left: 40,
                child: Tab(
                    icon: currentUser?.profilVerified == true
                        ? const Icon(
                            Icons.account_circle_outlined,
                            color: Colors.lightGreen,
                            size: 30,
                          )
                        : const Icon(
                            Icons.account_circle_outlined,
                            color: Colors.red,
                            size: 30,
                          )))
          ],
        )
      ],
    )

相关问题