android – error navigating to residence display or preliminary display based mostly on present consumer log in standing

0
22
android – error navigating to residence display or preliminary display based mostly on present consumer log in standing


Error:

Navigator operation requested with a context that doesn’t embrace a Navigator.
The context used to push or pop routes from the Navigator have to be that of a widget that may be a descendant of a Navigator widget.

the logic is as comply with:
if consumer is new and operating the app for the primary time, loading display, splash display, as soon as each day affirmation that may be a mounted affirmation to not be modified (“Within the midst of winter, I discovered there was inside me an invincible summer season.”) then preliminary display.
if the consumer is signed up and logged in, operating the app ought to present loading display, splash display, as soon as each day affirmation that’s pulled from the firestore affirmations randomly then residence display.

enter code right here

beneath is code inflicting the difficulty:

// Present circulate for logged-in customers
void _showAffirmationsAndNavigate() {
  print('Beginning _showAffirmationsAndNavigate...');

// Make sure the consumer state is appropriate
if (currentUser == null) {
  print('Error: currentUser is null throughout navigation.');
} else {
  print('Person is logged in with UID: ${currentUser!.uid}');
}

// Guarantee the precise context for navigation
WidgetsBinding.occasion.addPostFrameCallback((_) {
  Builder(builder: (BuildContext context) {
    if (currentUser != null) {
      print('Navigating to HomeView...');
      Navigator.of(context).pushReplacement(
        MaterialPageRoute(
          builder: (context) => HomeView(
            userId: currentUser!.uid,
            affirmationService: affirmationService,
          ),
        ),
      );
    } else {
      print('Navigating to InitialScreen for non-logged-in customers...');
      Navigator.of(context).pushReplacement(
        MaterialPageRoute(
          builder: (context) => const InitialScreen(),
        ),
      );
    }
    return Container(); // Dummy return, as Builder requires a widget to return
  });
});

}
”’
”’

LEAVE A REPLY

Please enter your comment!
Please enter your name here