-
-
Save red-star25/04e62715ab61da2b966f3d444cddfa58 to your computer and use it in GitHub Desktop.
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:bloc_auth/bloc/bloc/auth_bloc.dart'; | |
import 'package:bloc_auth/presentation/SignIn/sign_in.dart'; | |
import 'package:firebase_auth/firebase_auth.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
class Dashboard extends StatelessWidget { | |
const Dashboard({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
// Getting the user from the FirebaseAuth Instance | |
final user = FirebaseAuth.instance.currentUser!; | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Dashboard'), | |
), | |
body: BlocListener<AuthBloc, AuthState>( | |
listener: (context, state) { | |
if (state is UnAuthenticated) { | |
// Navigate to the sign in screen when the user Signs Out | |
Navigator.of(context).pushAndRemoveUntil( | |
MaterialPageRoute(builder: (context) => SignIn()), | |
(route) => false, | |
); | |
} | |
}, | |
child: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text( | |
'Email: \n ${user.email}', | |
style: const TextStyle(fontSize: 24), | |
textAlign: TextAlign.center, | |
), | |
user.photoURL != null | |
? Image.network("${user.photoURL}") | |
: Container(), | |
user.displayName != null | |
? Text("${user.displayName}") | |
: Container(), | |
const SizedBox(height: 16), | |
ElevatedButton( | |
child: const Text('Sign Out'), | |
onPressed: () { | |
// Signing out the user | |
context.read<AuthBloc>().add(SignOutRequested()); | |
}, | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment