Kitcc
Kitcc

Reputation: 3148

FLUTTER JUST_AUDIO Navigator.Push not working when finished play

I'm using the package Just_Audio. It's been working well, However now I want that when it finished playing if the user hasn't paid a Payment screen should open.

Here is the code:

void closeScreen() {


final _userHasPaid =
    Provider.of<User>(context, listen: false).user.testPaid;
print("USER PAID = ${_userHasPaid}");
if (_userHasPaid == false && widget.breathwork.breathType == "F") {
  print("got here");
  Navigator.push(
    context,
    MaterialPageRoute(
      builder: (context) {
        print(" and got here");
        return PaymentsScreen();
      },
    ),
  );
}

disposeAudio();
print("should pop now");
Navigator.pop(context);

}

Before I introduced the Navigator.push it all worked fine and close the screen with the Navigator.pop. However as soon as I add the push code, I do not get the PaymentsScreen and also the Navigator.pop at the end is no longer working.

I do see prints to the console for : print USER PAID print got here print should pop now

But not for: print got here.

Any help would be really appreciated, thanks

Upvotes: 0

Views: 176

Answers (1)

Mohamed Inshaf
Mohamed Inshaf

Reputation: 395

you can't call both Navigator.push and pop function at the same time, you have to go to payment page then you have to pop from there once the payment is done, and add the disposeAudio(); function before push to payment page

void closeScreen() {

disposeAudio();

final _userHasPaid =
    Provider.of<User>(context, listen: false).user.testPaid;
print("USER PAID = ${_userHasPaid}");
if (_userHasPaid == false && widget.breathwork.breathType == "F") {
  print("got here");
  Navigator.push(
    context,
    MaterialPageRoute(
      builder: (context) {
        print(" and got here");
        return PaymentsScreen();
      },
    ),
  );
}

Upvotes: 1

Related Questions