Skip to content

Instantly share code, notes, and snippets.

@elvan
Created November 24, 2020 04:20
Show Gist options
  • Save elvan/24356a02d4faa8b8946a62806e947df4 to your computer and use it in GitHub Desktop.
Save elvan/24356a02d4faa8b8946a62806e947df4 to your computer and use it in GitHub Desktop.
Flutter Riverpod and Firebase Auth example
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();
});
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(),
},
);
}
}
@robmagario
Copy link

Where is the rest of the code?
I was able to use the beginning of the code in my provider. Thanks a lot.

@SalahAdDin
Copy link

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