'How to make Gestures pass through a PopupRoute in flutter?
I am pushing a route which extends PopupRoute (which extends ModalRoute) on the navigator. This route does not cover the whole screen with its content widgets. But it is absorbing all the gestures even those not covered by its contents due to its barrier adjusted by the parent ModalRoute. Is there a simple way to pass the gestures that happen on "empty areas" on this route to the route under it (behind it)??
Solution 1:[1]
As I did in my question here, I had to modify flutter's source code to add the translucent behaviour to the popup barrier.
You can copy routes.dart into a new file custom_routes.dart and then in that file modify the function _buildModalBarrier of ModalRoute class like this (see the commented-out code):
Widget _buildModalBarrier(BuildContext context) {
...
else {
///////////////////////////////// comment this code
// barrier = ModalBarrier(
// dismissible: barrierDismissible, // changedInternalState is called if barrierDismissible updates
// semanticsLabel: barrierLabel, // changedInternalState is called if barrierLabel updates
// barrierSemanticsDismissible: semanticsDismissible,
// );
//////////////////////////////// add this code
barrier = Listener(
behavior: HitTestBehavior.translucent,
onPointerUp: (event){
print('event is $event');
Navigator.of(context).pop();
},
);
////////////////////////////////
}
...
}
But why not just create a Custom Route that extends ModalRoute?
You can do that but you need to re-implement all the logic that ModalRoute would have instead taken care of for you. So after hours of digging unfortunately this is the only way I found to do that. If someone has a better way tell me to update the answer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Haidar |
