Skip to content

Instantly share code, notes, and snippets.

@red-star25
Created January 8, 2022 09:40
Show Gist options
  • Save red-star25/04e62715ab61da2b966f3d444cddfa58 to your computer and use it in GitHub Desktop.
Save red-star25/04e62715ab61da2b966f3d444cddfa58 to your computer and use it in GitHub Desktop.
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