Created
December 8, 2021 02:18
-
-
Save csells/3f874c579ecb080acf7f029b01d14589 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
import 'package:flutter/material.dart'; | |
import 'package:firebase_core/firebase_core.dart'; | |
import 'package:firebase_auth/firebase_auth.dart'; | |
import 'package:flutterfire_ui/auth.dart'; | |
import 'firebase_options.dart'; | |
Future<void> main() async { | |
WidgetsFlutterBinding.ensureInitialized(); | |
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) => MaterialApp( | |
home: AuthenticationGate(), | |
); | |
} | |
class AuthenticationGate extends StatelessWidget { | |
const AuthenticationGate({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) => StreamBuilder<User?>( | |
stream: FirebaseAuth.instance.authStateChanges(), | |
builder: (context, snapshot) { | |
// User is not signed in - show a sign-in screen | |
if (!snapshot.hasData) { | |
return SignInScreen( | |
providerConfigs: [ | |
EmailProviderConfiguration(), | |
GoogleProviderConfiguration( | |
clientId: 'xxxx-xxxx.apps.googleusercontent.com', | |
), | |
], | |
); | |
} | |
return HomePage(); // show your app’s home page after login | |
}, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out the flutterfire_ui plugin and it's support for Google Sign-in: https://firebase.flutter.dev/docs/ui/auth/configuring-providers#google