This is very weird as creating a doc in the firestore database is a fairly easy and straightforward process. However, my doc is not being created. So, after user pays a fee the app created the records in the auth table in firebase, which works fine. Then it shoud create a record in the firestore. Here is the payment success screen, which should redirect to the other screen, but it just stuck there:
class PaymentSuccess extends StatefulWidget {
final String? email;
final String? password;
const PaymentSuccess( {Key? key, this.email, this.password, }) : super(key: key);
@override
State<PaymentSuccess> createState() => _PaymentSuccessState();
}
class _PaymentSuccessState extends State<PaymentSuccess> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
LoginViewModel viewModel = Provider.of<LoginViewModel>(context, listen: false);
viewModel.signUp(context, widget.email!, widget.password!);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: Stack(
children: <Widget>[
Container(
decoration: const BoxDecoration(
image: DecorationImage(image: AssetImage("assets/images/background.png"),
fit: BoxFit.cover,),
),
),
Container(
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.check_circle_rounded, color: Colors.green,size: 150,),
const SizedBox(height: 25,),
Text(Languages.of(context)!.paymentSuccess,
style: const TextStyle(fontSize: 25, color: Colors.white),),
const SizedBox(height: 20),
Text(Languages.of(context)!.plsWait,
style: const TextStyle(fontSize: 20, color: Colors.white),),
],
),
),
])
);
}
}
the LoginViewModel class' signUp method:
signUp(BuildContext context, String email, String password) async {
loading = true;
notifyListeners();
try {
UserCredential userCredential= await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: email, password: password);
debugPrint('userID -------> ${userCredential.user!uid}');
await usersRef
.doc(userCredential.user!.uid)
.set({
'id': userCredential.user!.uid,
'email': email,
'profilePic': '',
'username': 'User',
'isPaid': true,
'timestamp': Timestamp.now()
});
loading = false;
notifyListeners();
Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) =>
const EditProfile()));
}on FirebaseAuthException catch (e) {
loading = false;
notifyListeners();
errorDialog(context, e.message!);
} catch (e){
loading = false;
notifyListeners();
errorDialog(context, e.toString());
}
}
So, as was mentioned earlier the method does create the user in the authentication, but it does not set data in the firestore collection. I did create collection with some dummy doc and id field in it.
the debugPrint does printes the credentials, but then it stops working further....

I dont understand what I am missing here... The internet is stable and fast. Help appreciated very much!
I do get the error:
W/Firestore(11015): (24.2.2) [WatchStream]: (193087b) Stream closed with status: Status{code=UNAVAILABLE, description=Channel shutdownNow invoked, cause=null}.
but my rules are very simple:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow write: if request.auth.uid != null;
allow read: if request.auth.uid != null;
}
}
}