【问题标题】:Not click on Container in Stack不点击堆栈中的容器
【发布时间】:2021-10-26 01:43:09
【问题描述】:

堆栈小部件有问题。 我有一个包含两个孩子的堆栈:一个用 GestureDetector 包装的图像和一个容器 .当我单击 Container 上的任意位置时,Stack 中的最后一个子项会列出他的 onTap

我对 Flutter 非常陌生。

屏幕截图

这段代码

  sonItem(dynamic icon ,String text,Color color){
return  GestureDetector(
  onTap: () {
    print("dddddddddddddddd");
  },
  child: Container(

    width: 70,
    height: 100,
    margin: EdgeInsets.all(2),
    padding: EdgeInsets.all(2),

    child: Column(
      children: [
        Icon(icon ,color: color,),
        Text(text)
      ],
    ),
  ),
);

}

堆栈小部件有问题。 我有一个包含两个孩子的堆栈:一个用 GestureDetector 包装的图像和一个容器 .当我点击 Container 上的任意位置时,Stack 中最后一个的孩子都会列出他的 onTap

 body: Container(
            color: Colors.white,
            child: SingleChildScrollView(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  Container(
                    color:  Color(0xffF0F0F0),
                    height: 200,
                    child: Stack(
                      overflow: Overflow.visible,
                      alignment: Alignment.center,
                      children: [
                  
                        Positioned(
                            bottom: -170.0,
                            child: Container(
                              padding: EdgeInsets.only(top: 40 , right: 10, left: 10),
                              height: 250,
                              decoration: BoxDecoration(
                                color: Color(0xffFFFFFF),
                                borderRadius: BorderRadius.circular(30),
                                border: Border.all(
                                  width: 1,
                                  color: Colors.black,
                                  style: BorderStyle.solid,
                                ),
                              ),
                              child: Column(
                                children: [
                                  Text('company',
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                      fontSize: 24,
                                      color: Colors.black,
                                    ),
                                  ),
                                  Text("The number 2000"),
                                  RatingBar(
                                    rating: 3,
                                    icon:Icon(Icons.star,size:20,color: Colors.grey,),
                                    starCount: 5,
                                    spacing: 5.0,
                                    size: 20,
                                    isIndicator: false,
                                    allowHalfRating: true,
                                    onRatingCallback: (double value,ValueNotifier<bool> isIndicator){
                                      print('Number of stars-->  $value');
                                      //change the isIndicator from false  to true ,the       RatingBar cannot support touch event;
                                      isIndicator.value=true;
                                    },
                                    color: Colors.amber,
                                  ),
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                                    children: [
                                      sonItem(Icons.phone,"call us",Colors.green),
                                      sonItem(Icons.location_on_outlined,"location",Colors.red),
                                      sonItem(Icons.facebook,"FaceBook",Colors.blue),
                                      sonItem(Icons.add_ic_call_outlined,"whatsapp",Colors.green)
                                    ],
                                  )
                                ],),
                            )),
                     

【问题讨论】:

  • 点击优先级获取自下而上的堆栈子级。
  • 删除bottom:-170.0后问题解决了,但我在设计中需要它

标签: flutter


【解决方案1】:

试试下面的代码希望对你有帮助

Stack(
children: <Widget>[
    //your InkWell or GestureDetector Widget
    InkWell(
        child: Container(
        // your child Widget
         ),
        onTap: () {},
    ),
    Positioned(),
  ]
),

【讨论】:

    【解决方案2】:

    当我删除底部时问题解决了:-170.0, 但我在设计中需要它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-03
      • 1970-01-01
      • 2022-01-23
      • 2019-01-18
      • 2023-03-27
      • 1970-01-01
      • 2010-10-23
      相关资源
      最近更新 更多