79673345

Date: 2025-06-20 12:04:23
Score: 1
Natty:
Report link

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.

Reasons:
  • Whitelisted phrase (-1): hope this helps
  • RegEx Blacklisted phrase (2): I am a beginner
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Mirza AbdulMoeed