简体   繁体   English

flutter firestore 未在云 firestore 数据库中创建文档

[英]flutter firestore not creating a document in the cloud firestore database

This is very weird as creating a doc in the firestore database is a fairly easy and straightforward process.这很奇怪,因为在 firestore 数据库中创建文档是一个相当简单和直接的过程。 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.因此,在用户支付费用后,应用程序在 firebase 中的 auth 表中创建了记录,效果很好。 Then it shoud create a record in the firestore.然后它应该在 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: LoginViewModel 类的注册方法:

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.因此,如前所述,该方法确实会在身份验证中创建用户,但不会在 firestore 集合中设置数据。 I did create collection with some dummy doc and id field in it.我确实在其中创建了一些虚拟文档和 id 字段的集合。

the debugPrint does printes the credentials, but then it stops working further.... debugPrint 确实打印了凭据,但随后它停止了进一步工作.... 登录这里

I dont understand what I am missing here... The inte.net is stable and fast.我不明白我在这里缺少什么...... inte.net 稳定且快速。 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;
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM