I created an extension method of the Navigator class as shown below:
extension on Navigator {
static void navigatorToLoginPage(BuildContext context) {
Navigator.push(context, MaterialPageRoute(
builder: (context) =>
ChangeNotifierProvider(
create: (context) => LoginViewModel(),
child: LoginPage()
)
));
}
}
Now, I am having problems calling it from another file.
Inside the build function of another widget, I tried calling the Navigator.navigateToLoginPage but it does not recognize the navigateToLoginPage as a static function.
onTap: () {
Navigator.navigateToLoginPage(context); // this is not working. Not recognizing the navigateToLoginPage
_navigateToRegisterPage(context);
}),
Am I missing something?
UPDATE: I was able to achieve it using the following code:
extension AppNavigator on Navigator {
static void navigateToLoginPage(BuildContext context) {
Navigator.push(context, MaterialPageRoute(
builder: (context) =>
ChangeNotifierProvider(
create: (context) => LoginViewModel(),
child: LoginPage()
), fullscreenDialog: true
));
}
}