'flutter : [firebase_auth/unknown] Given String is empty or null
my code isn't add person to firebase and isn't reach to the user in authentication. But I can't understand why.
This part is firebase part.
final FirebaseAuth _auth = FirebaseAuth.instance; final FirebaseFirestore _firestore = FirebaseFirestore.instance; Future<User?> signIn(String email, String password) async { try { var user = await _auth.signInWithEmailAndPassword( email: email, password: password); print(email); print(password); return user.user; } catch (e) { print(e); } } signOut() async { return await _auth.signOut(); } Future<User?> createPerson(String email, String password) async { try { var user = await _auth.createUserWithEmailAndPassword( email: email, password: password); await _firestore.collection("Person").doc(user.user?.uid).set({ "email": email, "password": password, }); return user.user; } catch (e) { print(e); }}} ```This part is input field that I received the email.
final String hintText;
final IconData icon;
final ValueChanged<String>? onChanged;
final TextEditingController? controller;
const RoundedInputField({
Key? key,
this.hintText = "",
this.icon = Icons.person,
this.onChanged,
this.controller,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return TextFieldContainer(
child: TextField(
onChanged: onChanged,
controller: controller,
- Password field
class PasswordField extends StatefulWidget {
final ValueChanged<String>? onChanged;
final TextEditingController? controller;
const PasswordField({
Key? key,
this.onChanged, this.controller,
}) : super(key: key);
@override
State<PasswordField> createState() => _PasswordFieldState();
}
class _PasswordFieldState extends State<PasswordField> {
bool _isObscure = true;
@override
Widget build(BuildContext context) {
return TextFieldContainer(
child: TextField(
onChanged: widget.onChanged,
obscureText: _isObscure,
controller: widget.controller,
...
- And this is the sign up part where I use email and password input field
RoundedInputField(
hintText: "Your Email",
onChanged: (value) {},
),
PasswordField(
onChanged: (value) {},
),`enter code here`
RoundedButton(
text: "SIGNUP",
press: () {
_authService
.createPerson(_emailController.text, _passwordController.text)
.then((value) {
return Navigator.push(context,
MaterialPageRoute(builder: (context) => LoginScreen()));
});
},
),
I looked some questions and answers but I can't solve this. Please help me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
