flutter 常量应用程序=初始化应用程序(firebaseConfig);常量授权=获取授权(应用程序);常量数据库= getFirestore();

lmyy7pcs  于 2023-02-25  发布在  Flutter
关注(0)|答案(1)|浏览(116)

我想为Flutter应用程序使用Firestore,但抛出错误。它抛出[core/no-options] Firebase:当未通过源部署到宿主时,需要提供选项。另请参阅:https://futter.dev/docs/testing/errors。也不会让整个脚手架承受荷载。

try {
        await FirebaseAuth.instance.createUserWithEmailAndPassword(
            email: email!.text, password: pass!.text);
        Navigator.pushReplacement(
          context,
          MaterialPageRoute(
            builder: (context) => Home(),
          ),
        );
        FirebaseFirestore.instance
            .collection('userdata')
            .doc(u_name?.text)
            .get()
            .then(
          (DocumentSnapshot documentSnapshot) {
            if (documentSnapshot.exists) {
              final snackBar = SnackBar(
                content: const Text('Username already been taken.'),
                backgroundColor: (Colors.black12),
                action: SnackBarAction(
                  label: 'Dismiss',
                  onPressed: () {},
                ),
              );
              ScaffoldMessenger.of(context).showSnackBar(snackBar);
            } else {
              FirebaseFirestore.instance
                  .collection('userdata')
                  .doc(u_name?.text)
                  .set(
                {
                  'f_name': f_name?.text,
                  'l_name': l_name?.text,
                  'username' : u_name?.text,
                  'email' : email?.text,
                  'pass' : pass?.text,
                },
              );
            }
          },
        );
      }
qco9c6ql

qco9c6ql1#

在使用任何其他Firebase服务之前,必须初始化Firebase应用程序,因此请确保首先调用initializeApp()函数,如How can I provide options when not being deployed to hosting via source?中所述

相关问题