Custom Widget navigation

I want to navigate to another page onTap from a custom widget like this:

Navigator.of(appContext).pushNamed('PageName');

But when doing this, onTap I only get the following error:

Navigator.onGenerateRoute was null, but the route named

So, what is the correct way to do this? Currently, I am using the context available to the widget. Maybe this context is incorrect?

1
3 replies