I am doing the registration with firebase and I got an issue the signUp button . I created a file Firebase_auth_services.dart that has this code
class FirebaseAuthServices {
FirebaseAuth _auth = FirebaseAuth.instance;
Future<User?> signUpWithEmailAndPassword(
String email, String password) async {
try {
UserCredential credential = await _auth.createUserWithEmailAndPassword(
email: email, password: password);
return credential.user;
} catch (e) {
print('Some error occured');
}
return null;
}
Future<User?> signInWithEmailAndPassword(
String email, String password) async {
try {
UserCredential credential = await _auth.signInWithEmailAndPassword(
email: email, password: password);
return credential.user;
} catch (e) {
print('Some error occured');
}
return null;
}
}
and I created this method in my signup page :
class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});
@override
_LoginPageState createState() => _LoginPageState();
}
var elements1 = [
'Customer',
'Business',
];
String dropdownvalue = 'Customer';
TextEditingController _usernameController = TextEditingController();
TextEditingController _emailController = TextEditingController();
TextEditingController _passwordController = TextEditingController();
bool isSigningUp = false;
final FirebaseAuthServices _auth = FirebaseAuthServices();
class _LoginPageState extends State<LoginScreen> {
@override
void dispose() {
_usernameController.dispose();
_emailController.dispose();
_passwordController.dispose();
super.dispose();
}
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Padding(
padding: const EdgeInsets.only(top: 50.0, left: 30, right: 30),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Logo(),
SignUpButton(),
SizedBox(
height: 30,
),
Container(
height: 62,
width: 350,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32),
)),
onPressed: _signUp,
child: Text(
'Sign Up',
style: TextStyle(color: Colors.white),
),
),
),
SizedBox(
height: 10,
),
LoginButton(),
],
)),
);
}
void _signUp() async {
String username = _usernameController.text;
String email = _emailController.text;
String password = _passwordController.text;
User? user = await _auth.signUpWithEmailAndPassword(email, password);
if (user != null) {
print("User is successfully created");
Navigator.pushNamed(
context, "/Users/lilianasanda/influfit/lib/Homepage.dart");
} else {
print("Some error happend");
}
}
}
and this is the error I received :
I also changed that path in _signUp method with Navigator.pushNamed(
context, “/home”) but I am receiving the same error