Reputation: 3148
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
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