My code snippet is as follows for an elevated button:
onPressed: () async {
var docRef = await context
.read<FirestoreRepository>()
.firestore
.collection('users')
.doc(userData.selfRef.id)
.collection('checkout_sessions')
.add({
'price':
pricePlans.first.selfRef.id,
'success_url':
'https://success.com',
'cancel_url':
'https://cancel.com'
});
debugPrint(
'doc added');
docRef
.snapshots()
.listen((ds) {
if (ds.exists) {
var url = ds.get('url'); //Is there a way to get url using cubit inside a function?
if (context.mounted) {
Navigator.push(context, MaterialPageRoute(builder: (_) {
return CheckoutPage(url: url);
}));
I am getting an uncaught exception breakpoint at docRef.snapshots(). Why does that happen? What is the fix?