El caso es que soy nuevo en flutter, antes venia de Android Studio y todas esta cosas las hacia como si nada. En modo debug la app antes funcionaba, genere el SHA1 para meterlo en firebase... Hasta ahí todo bien. El problema vino cuando quise hacer la apk de la app que estoy desarrollando, y como os imaginareis no funcionaba. Visité varias paginas donde explicaban como solucionar este problema pero nada, de hecho ahora estoy pero porque no me inicia sesión ni en debug :(. ¿Alguna ayuda de algún experto?. La verdad es que no se que tocar más. Por si es de ayuda mi IDE es Visual Studio Code.
import 'package:TodosApp/Screens/profilescreen.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'bottomNavBar.dart';
void main() => runApp(LoginPage());
class LoginPage extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: GoogleSignApp(),
);
}
}
class GoogleSignApp extends StatefulWidget {
@override
_GoogleSignAppState createState() => _GoogleSignAppState();
}
class _GoogleSignAppState extends State<GoogleSignApp> {
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
final GoogleSignIn _googlSignIn = new GoogleSignIn();
Future<FirebaseUser> _signIn(BuildContext context) async {
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('Sign in'),
));
final GoogleSignInAccount googleUser = await _googlSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
FirebaseUser userDetails =
await _firebaseAuth.signInWithCredential(credential);
ProviderDetails providerInfo = new ProviderDetails(userDetails.providerId);
List<ProviderDetails> providerData = new List<ProviderDetails>();
providerData.add(providerInfo);
UserDetails details = new UserDetails(
userDetails.providerId,
userDetails.displayName,
userDetails.photoUrl,
userDetails.email,
providerData,
);
/*Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new ProfileScreen(detailsUser: details),
),
);*/
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new BottomNavBar(detailsUser: details)));
return userDetails;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Builder(
builder: (context) => Stack(
fit: StackFit.expand,
children: <Widget>[
Center(
child: Image.network(
'https://images.unsplash.com/photo-1518050947974-4be8c7469f0c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60',
fit: BoxFit.fill,
color: Color.fromRGBO(255, 255, 255, 0.6),
colorBlendMode: BlendMode.modulate),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 10.0),
Container(
width: 250.0,
child: Align(
alignment: Alignment.center,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)),
color: Color(0xffffffff),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Icon(
FontAwesomeIcons.google,
color: Color(0xffCE107C),
),
SizedBox(width: 10.0),
Text(
'Sign in with Google',
style: TextStyle(
color: Colors.black, fontSize: 18.0),
),
],
),
onPressed: () => _signIn(context)
.then((FirebaseUser user) => print(user))
.catchError((e) => print(e)),
),
)),
Container(
width: 250.0,
child: Align(
alignment: Alignment.center,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)),
color: Color(0xffffffff),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Icon(
FontAwesomeIcons.facebookF,
color: Color(0xff4754de),
),
SizedBox(width: 10.0),
Text(
'Sign in with Facebook',
style: TextStyle(
color: Colors.black, fontSize: 18.0),
),
],
),
onPressed: () {},
),
)),
Container(
width: 250.0,
child: Align(
alignment: Alignment.center,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)),
color: Color(0xffffffff),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Icon(
FontAwesomeIcons.solidEnvelope,
color: Color(0xff4caf50),
),
SizedBox(width: 10.0),
Text(
'Sign in with Email',
style: TextStyle(
color: Colors.black, fontSize: 18.0),
),
],
),
onPressed: () {},
),
)),
],
),
],
),
),
);
}
}
class UserDetails {
final String providerDetails;
final String userName;
final String photoUrl;
final String userEmail;
final List<ProviderDetails> providerData;
UserDetails(this.providerDetails, this.userName, this.photoUrl,
this.userEmail, this.providerData);
}
class ProviderDetails {
ProviderDetails(this.providerDetails);
final String providerDetails;
}
Y el error que me da es este: Exception has occurred. PlatformException (PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 12500: , null)) en esta linea--> final GoogleSignInAccount googleUser = await _googlSignIn.signIn();. Lo siento por no dejarlo con pantallazos pero soy nuevo en stackoverflow y totavia no manejo esto muy bien