I want to access from Sign In to Home window, but when I try to sign in with existing account the button doesn't work and the window stays the same.
import 'package:finalproject/Pages/home.dart';
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => new _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
String _email, _password;
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: Text('Sign in'),
),
body: Form(
key: _formKey,
child: Column(
children: <Widget>[
TextFormField(
validator: (input) {
if (input.isEmpty) {
return ' Write your email';
}
return null;
},
onSaved: (input) => _email = input,
decoration: InputDecoration(labelText: ' Email'),
),
TextFormField(
validator: (input) {
if (input.length < 6) {
return ' Write your password';
}
return null;
},
onSaved: (input) => _password = input,
decoration: InputDecoration(labelText: ' Password'),
obscureText: true,
),
RaisedButton(
onPressed: signIn,
child: Text('Sign in'),
),],),),);}
void signIn() async {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
try {
// ignore: deprecated_member_use
UserCredential authResult = await FirebaseAuth.instance
.signInWithEmailAndPassword(email: _email, password: _password);
final User user = authResult.user;
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Home()),
);
} catch (e) {
print(e.message);
}}}}
Also, I always get this message after I press the Sign in button.
I/flutter ( 3130): No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
Maybe this could be the reason of it?