-
-
Save red-star25/4f9a90a70cd3dd60e54fdd4503783e22 to your computer and use it in GitHub Desktop.
SignIn Page with BlocConsumer implemented
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/data/repositories/auth_repository.dart'; | |
import 'package:bloc_auth/presentation/Dashboard/dashboard.dart'; | |
import 'package:bloc_auth/presentation/SignUp/sign_up.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
class SignIn extends StatelessWidget { | |
//.... | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text("SignIn"), | |
), | |
body: BlocListener<AuthBloc, AuthState>( | |
listener: (context, state) { | |
if (state is Authenticated) { | |
// Navigating to the dashboard screen if the user is authenticated | |
Navigator.pushReplacement(context, | |
MaterialPageRoute(builder: (context) => const Dashboard())); | |
} | |
if (state is AuthError) { | |
// Showing the error message if the user has entered invalid credentials | |
ScaffoldMessenger.of(context) | |
.showSnackBar(SnackBar(content: Text(state.error))); | |
} | |
}, | |
child: BlocBuilder<AuthBloc, AuthState>( | |
builder: (context, state) { | |
if (state is Loading) { | |
// Showing the loading indicator while the user is signing in | |
return const Center( | |
child: CircularProgressIndicator(), | |
); | |
} | |
if (state is UnAuthenticated) { | |
// Showing the sign in form if the user is not authenticated | |
return Center(child: //...) | |
} | |
return Container(); | |
}, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment