The ontap click event of GestureDetector generally takes the size of the child as the click area. Sometimes, in order to increase the click area, the padding will be set for the child, but the click effect will still not be achieved after the padding part is set. At this time, it needs to be configured

First, set the background color of the Container

return GestureDetector( onTap: (){ }, child: Container( height: 50, width: 100, padding: EdgeInsets. Symmetric (horizontal: 25), /// here set the color color: color.transparent,);Copy the code

Second, setting the GestureDetector behaviors: HitTestBehavior. Translucent

Return GestureDetector (/ / / this setting behaviors behaviors: HitTestBehavior. Translucent, onTap: () {}, child: Container (height: 50, width: 100, padding: EdgeInsets.symmetric(horizontal: 25), ), );Copy the code

So behavior has three properties here

HitTestBehavior. Opaque and HitTestBehavior. Translucent similarities is that can expand click scope, let oneself the whole regional response to the click event HitTestBehavior. Opaque And HitTestBehavior translucent difference lies in the opaque block the next layer of elements for events, and translucent not as opaque will modify hitTestSelf return value, Let oneself through the end of the test and then let the parent class for other subclasses of crash test HitTestBehavior. Translucent penetration is conditional, can only be "blank space" to penetrate. The blank area here means that no child in the clicked area can pass the crash testCopy the code