Skip to content

Instantly share code, notes, and snippets.

@red-star25
Created January 8, 2022 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save red-star25/4f9a90a70cd3dd60e54fdd4503783e22 to your computer and use it in GitHub Desktop.
Save red-star25/4f9a90a70cd3dd60e54fdd4503783e22 to your computer and use it in GitHub Desktop.
SignIn Page with BlocConsumer implemented
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