Skip to content

Instantly share code, notes, and snippets.

@red-star25
Created January 8, 2022 09:35
Show Gist options
  • Save red-star25/a1158044ca019d252d671e451b87721e to your computer and use it in GitHub Desktop.
Save red-star25/a1158044ca019d252d671e451b87721e to your computer and use it in GitHub Desktop.
SignUp 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/SignIn/sign_in.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class SignUp extends StatelessWidget {
//...
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("SignUp"),
),
body: BlocConsumer<AuthBloc, AuthState>(
listener: (context, state) {
if (state is Authenticated) {
// Navigating to the dashboard screen if the user is authenticated
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => const Dashboard(),
),
);
}
if (state is AuthError) {
// Displaying the error message if the user is not authenticated
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(state.error)));
}
},
builder: (context, state) {
if (state is Loading) {
// Displaying the loading indicator while the user is signing up
return const Center(child: CircularProgressIndicator());
}
if (state is UnAuthenticated) {
// Displaying the sign up 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