我正在尝试使用 firebase 注册用户,但我收到了 firebase 通道错误 以下是代码
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:todo_fb_provider/models/usermodel.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class SignUpSerivce {
final FirebaseAuth _auth = FirebaseAuth.instance;
final FirebaseFirestore fireStore = FirebaseFirestore.instance;
Future<void> createUser(BuildContext context, String userId, String userName,
String name, String password, String gender, String email) async {
try {
UserCredential userCredential = await _auth
.createUserWithEmailAndPassword(email: email, password: password);
String uid = userCredential.user!.uid;
Usermodel usermodel = Usermodel(
email: email,
userName: userName,
userId: userId,
gender: gender,
password: password,
name: name);
await fireStore.collection('users').doc(uid).set(usermodel.toMap());
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('User Created Successfully')),
);
print('User Created');
} on FirebaseException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed with error $e')),
);
print(e);
} catch (e) {
print(e);
}
}
}
我希望它使用提供的详细信息创建一个用户,但我得到以下内容
I/flutter (12898): [firebase_auth/channel-error] "dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.createUserWithEmailAndPassword".
所有 Firebase 权限均设置为 true
确保创建用户时没有传递空参数。如果发送了正确的参数但仍然存在问题,则该电子邮件可能存在现有数据,如果是这样,请在更新记录时添加 setOptions。
await fireStore.collection('users').doc(uid).set({usermodel.toMap()}, SetOptions(merge: true));