Created
May 26, 2021 19:34
-
-
Save PeterHdd/54d33dc2bd89bd4985efe4d21d263b35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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