onTapRecognizeGesture method
Creates a TapGestureRecognizer that navigates to a specified route when tapped.
routeName
is the name of the route to navigate to.
args
are the optional arguments to pass to the route.
Implementation
TapGestureRecognizer onTapRecognizeGesture(
{String? routeName, Map<String, dynamic>? args}) {
void onTap() {
try {
if (routeName != null) {
if (context != null) {
Navigator.of(context!).pushNamed(routeName, arguments: args);
} else if (navigatorKey != null) {
navigatorKey!.currentState!.pushNamed(routeName, arguments: args);
}
}
} catch (e) {
print('Error in onTap: $e');
}
}
TapGestureRecognizer gestureRecognizer = TapGestureRecognizer()
..onTap = onTap;
return gestureRecognizer;
}