Reputation: 81
I am trying to make an authentication using flutter and firebase and i always face this problem. I have enabled email and password authetication in firebase and also addded the SHA-1 and SHA-256 keys,but still not able to resolve the error. I am getting the error that 'The email is badly formmated.' The error is given below.
W/DynamiteModule( 7351): Local module descriptor class for providerinstaller not found.
W/ConnectivityManager.CallbackHandler( 7351): callback not found for CALLBACK_AVAILABLE message
I/DynamiteModule( 7351): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller( 7351): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
[GETX] Instance "GetMaterialController" has been created
[GETX] Instance "GetMaterialController" has been initialized
[GETX] GOING TO ROUTE /SignUp
W/IInputConnectionWrapper( 7351): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 7351): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 7351): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 7351): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7351): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 7351): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7351): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7351): setComposingText on inactive InputConnection
W/IInputConnectionWrapper( 7351): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7351): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7351): setComposingText on inactive InputConnection
W/IInputConnectionWrapper( 7351): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7351): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 7351): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 7351): getTextAfterCursor on inactive InputConnection
I/FirebaseAuth( 7351): [FirebaseAuth:] Preparing to create service connection to fallback implementation
W/System ( 7351): Ignoring header X-Firebase-Locale because its value was null.
I/flutter ( 7351): [firebase_auth/invalid-email] The email address is badly formatted.
Here goes the form validation page.
// ignore_for_file: prefer_const_constructors, prefer_final_fields, prefer_const_literals_to_create_immutables
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:howyoudoin/controller/auth_methods.dart';
import 'package:howyoudoin/utils/theme.dart';
import 'package:howyoudoin/widgets/widgets.dart';
class SignUp extends StatefulWidget {
const SignUp({Key? key}) : super(key: key);
@override
_SignUpState createState() => _SignUpState();
}
class _SignUpState extends State<SignUp> {
TextEditingController _emailController = TextEditingController();
TextEditingController _passwordController = TextEditingController();
TextEditingController _username = TextEditingController();
TextEditingController _bioController = TextEditingController();
@override
void dispose() {
// TODO: implement dispose
super.dispose();
_emailController.dispose();
_passwordController.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 22),
width: double.infinity,
child: Column(
children: [
Expanded(
child: Container(),
flex: 1,
),
SizedBox(
height: 24,
),
TextFieldInput(
textEditingController: _username,
hintText: "UserName",
textInputType: TextInputType.text,
isPass: false,
),
SizedBox(
height: 20,
),
TextFieldInput(
textEditingController: _emailController,
hintText: "Enter Your Email",
textInputType: TextInputType.emailAddress,
isPass: false,
),
SizedBox(
height: 20,
),
TextFieldInput(
textEditingController: _passwordController,
hintText: "Password",
textInputType: TextInputType.text,
isPass: true,
),
SizedBox(
height: 20,
),
TextFieldInput(
textEditingController: _bioController,
hintText: "Bio",
textInputType: TextInputType.text,
isPass: false,
),
SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () async {
String res = await AuthMethods().signUpUser(
email: _emailController.toString(),
password: _passwordController.toString(),
username: _username.toString(),
bio: _bioController.toString(),
);
print(res);
},
child: Text("Sign Up"),
style: ElevatedButton.styleFrom(
primary: blueColor,
minimumSize: Size(double.infinity, 50),
),
),
Expanded(
child: Container(),
flex: 1,
),
],
),
),
),
);
}
}
And the AuthMethod Code is
import 'dart:typed_data';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:howyoudoin/resources/storage_methods.dart';
class AuthMethods {
final FirebaseAuth _auth = FirebaseAuth.instance;
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
Future<String> signUpUser(
{required String email,
required String password,
required String username,
required String bio}) async {
String res = "Some error occured";
try {
if (email.isNotEmpty ||
password.isNotEmpty ||
bio.isNotEmpty ||
username.isNotEmpty) {
UserCredential cred = await _auth.createUserWithEmailAndPassword(
email: email, password: password);
print(cred.user!.uid);
await _firestore.collection('users').doc(cred.user!.uid).set({
'username': username,
'uid': cred.user!.uid,
'email': email,
'bio': bio
});
res = "success";
}
} catch (err) {
res = err.toString();
}
return res;
}
}
Upvotes: 1
Views: 3445
Reputation: 1
Use this instead in the AuthMethod
Code for signup. Basically, if we provide an email address with a space, then the authentication error occurs. The trim method will remove any extra whitespace.
{
'username':username.trim(),
'uid':credential.user!.uid,
'name':name.trim(),
'email':email.trim(),
'bio': bio.trim()
}
Upvotes: 0
Reputation: 598951
Calling toString()
on a TextEditingController
gives you a description of the controller, not the value of the underlying text field. So this seems wrong:
String res = await AuthMethods().signUpUser(
email: _emailController.toString(),
password: _passwordController.toString(),
username: _username.toString(),
bio: _bioController.toString(),
);**
To get the value of the actual text field, use the text
property of the controller instead. So:
String res = await AuthMethods().signUpUser(
email: _emailController.text,
password: _passwordController.text,
username: _username.text,
bio: _bioController.text,
);
Upvotes: 4
Reputation: 450
The answer to the question is very simple.. you are using:
email: _emailController.toString(),
password: _passwordController.toString(),
username: _username.toString(),
bio: _bioController.toString(),
but you should be using
email: _emailController.text,
password: _passwordController.text,
username: _username.text,
bio: _bioController.text,
kindly upvote if useful
Upvotes: 2