Skip to content

Instantly share code, notes, and snippets.

@PeterHdd
Created May 26, 2021 19:34
Show Gist options
  • Save PeterHdd/54d33dc2bd89bd4985efe4d21d263b35 to your computer and use it in GitHub Desktop.
Save PeterHdd/54d33dc2bd89bd4985efe4d21d263b35 to your computer and use it in GitHub Desktop.
class GoogleSignIn extends StatefulWidget {
GoogleSignIn({Key? key}) : super(key: key);
@override
_GoogleSignInState createState() => _GoogleSignInState();
}
class _GoogleSignInState extends State<GoogleSignIn> {
bool isLoading = false;
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return !isLoading? SizedBox(
width: size.width * 0.8,
child: OutlinedButton.icon(
icon: FaIcon(FontAwesomeIcons.google),
onPressed: () async {
setState(() {
isLoading = true;
});
FirebaseService service = new FirebaseService();
try {
await service.signInwithGoogle();
Navigator.pushNamedAndRemoveUntil(context, Constants.homeNavigate, (route) => false);
} catch(e){
if(e is FirebaseAuthException){
showMessage(e.message!);
}
}
setState(() {
isLoading = false;
});
},
label: Text(
Constants.textSignInGoogle,
style: TextStyle(
color: Constants.kBlackColor, fontWeight: FontWeight.bold),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Constants.kGreyColor),
side: MaterialStateProperty.all<BorderSide>(BorderSide.none)),
),
) : CircularProgressIndicator();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment