I have just found the laziest possible approach lol.
Just enter this:
print(context.widget.runtimeType);
Then get the Boolean value using the following:
context.widget.runtimeType == LoginPage;
Based on this, I created this function which pops the dialogue if the current screen / Widget is LoginScreen() where the function is called, otherwise the function takes us to the loginscreen.
onOKPressed: () {
final bool isLoginPage = Navigator.of(context).canPop() &&
context.widget.runtimeType == LoginPage;
if (isLoginPage) {
Navigator.pop(context);
} else {
Navigator.pushAndRemoveUntil(
context,
CupertinoPageRoute(builder: (_) => const LoginPage()),
(route) => false,
);
}
}
I am a beginner learning Flutter so far, but still hope this helps lol.