Flutter點擊事件的穿透,父元素點擊事件覆蓋了子元素點擊的問題


在web 中類似的情況的都被成為點擊穿透事件

在flutter中 ,組件的嵌套 也存在類似情況,flutter中的所有點擊事件 一層一層源碼找 最終都是 

 

有興趣可以去看官方文檔

https://flutterchina.club/gestures/

 

GestureDetector點擊 組件的源碼中的behavior 屬性

 

三個內容 枚舉 值

 

//方法1
 
...
InkWell(
   onTap: () {},
   child: GestureDetector(
                              behavior:HitTestBehavior.translucent,
                              onTap:(){
                                print("___test");
                                print("---");
                              },
                              child: Text("點擊",
                              
                              ),
  ),
                            
                   
 
);
 
...

  

//方法2
 
...
 
InkWell(
    onTap:(){},
    child: Container(
                              color:Colors.transparent,//透明顏色
                              child: GestureDetector(
 
                              onTap:(){
                                print("___test");
                                print("---");
                              },
                              child: Text("點擊",
                              style:TextStyleConstant().blue_16,
                              ),
                              ),
     ),
)
 
....

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM