Created
November 24, 2020 04:20
-
-
Save elvan/24356a02d4faa8b8946a62806e947df4 to your computer and use it in GitHub Desktop.
Flutter Riverpod and Firebase Auth example
This file contains 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:firebase_auth/firebase_auth.dart'; | |
import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
final firebaseAuthProvider = Provider<FirebaseAuth>((ref) { | |
return FirebaseAuth.instance; | |
}); | |
final authStateChangesProvider = StreamProvider<User>((ref) { | |
return ref.watch(firebaseAuthProvider).authStateChanges(); | |
}); |
This file contains 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:hooks_riverpod/hooks_riverpod.dart'; | |
import 'auth/auth_providers.dart'; | |
import 'auth/email_login_screen.dart'; | |
import 'auth/login_screen.dart'; | |
import 'home/home_screen.dart'; | |
class CareerCenterApp extends ConsumerWidget { | |
@override | |
Widget build(BuildContext context, ScopedReader watch) { | |
final user = watch(authStateChangesProvider).data?.value; | |
return MaterialApp( | |
title: 'Career Center', | |
theme: ThemeData( | |
primarySwatch: Colors.indigo, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: user != null ? HomeScreen() : LoginScreen(), | |
routes: { | |
EmailLoginScreen.route: (context) => EmailLoginScreen(), | |
}, | |
); | |
} | |
} |
I tried with the same code and it didn't work for me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where is the rest of the code?
I was able to use the beginning of the code in my provider. Thanks a lot.