Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX login UI and ADD Login Form Validation #153

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions app/google-services.json

This file was deleted.

12 changes: 0 additions & 12 deletions app/monumento-277103-9b64bd53f3b8.json

This file was deleted.

4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
android:name="android.hardware.camera.ar"
android:required="false" />

<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="31" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ class Unauthenticated extends AuthenticationState {

@override
List<Object> get props => [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:email_validator/email_validator.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:monumento/blocs/login_validation/login_validation_event.dart';
import 'package:monumento/blocs/login_validation/login_validation_state.dart';

class LoginValidationBloc
extends Bloc<LoginValidationEvent, LoginValidationState> {
LoginValidationBloc(LoginValidationState initialState) : super(initialState) {
on<LoginTextChangedEvent>((event, emit) {
if (event.emailValue == "" && EmailValidator.validate(event.emailValue)) {
emit(LoginValidationErrorState("Please enter a valid email address"));
}
else if(event.passwordValue.length<6){
emit(LoginValidationErrorState("Please enter a vlaid password"));
}
else{
emit(LoginValidationValidState());
}
});

// on<LoginSubmittedEvent>((event, emit) {});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
abstract class LoginValidationEvent{}

class LoginTextChangedEvent extends LoginValidationEvent{
final String emailValue;
final String passwordValue;
LoginTextChangedEvent(this.emailValue, this.passwordValue);
}

class LoginSubmittedEvent extends LoginValidationEvent{
final String email;
final String password;
LoginSubmittedEvent(this.email, this.password);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
abstract class LoginValidationState{}

class LoginValidationInitialState extends LoginValidationState{}

class LoginValidationValidState extends LoginValidationState{}

class LoginValidationErrorState extends LoginValidationState{
final String errorMessage;
LoginValidationErrorState(this.errorMessage);
}
8 changes: 8 additions & 0 deletions monumento_module/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:monumento/blocs/feed/feed_bloc.dart';
import 'package:monumento/blocs/login_validation/login_validation_bloc.dart';
import 'package:monumento/navigation/route_generator.dart';
import 'package:monumento/resources/authentication/authentication_repository.dart';
import 'package:monumento/resources/monuments/monument_repository.dart';
Expand All @@ -18,6 +19,8 @@ import 'package:monumento/ui/screens/app_intro/app_intro.dart';
import 'package:monumento/ui/screens/home/home_screen.dart';
import 'package:firebase_core/firebase_core.dart';

import 'blocs/login_validation/login_validation_state.dart';

Future<Null> main() async {
WidgetsFlutterBinding.ensureInitialized();
//TODO : Remove firebase initialization for faster app startup
Expand All @@ -42,6 +45,7 @@ class _MyAppState extends State<MyApp> {
LoginRegisterBloc _loginRegisterBloc;
BookmarkedMonumentsBloc _bookmarkedMonumentsBloc;
FeedBloc _feedBloc;
LoginValidationBloc _loginValidationBloc;

@override
void initState() {
Expand All @@ -56,6 +60,7 @@ class _MyAppState extends State<MyApp> {
firebaseMonumentRepository: _monumentRepository);
_feedBloc = FeedBloc(socialRepository: _socialRepository);
_authenticationBloc.add(AppStarted());
_loginValidationBloc=LoginValidationBloc(LoginValidationInitialState());
}

@override
Expand All @@ -82,6 +87,9 @@ class _MyAppState extends State<MyApp> {
BlocProvider<FeedBloc>(
create: (_) => _feedBloc,
),
BlocProvider<LoginValidationBloc>(
create: (_) => _loginValidationBloc,
)
],
child: AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
Expand Down
50 changes: 36 additions & 14 deletions monumento_module/lib/ui/screens/login/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:monumento/blocs/authentication/authentication_bloc.dart';
import 'package:monumento/blocs/login_register/login_register_bloc.dart';
import 'package:monumento/blocs/login_validation/login_validation_bloc.dart';
import 'package:monumento/blocs/login_validation/login_validation_event.dart';
import 'package:monumento/navigation/arguments.dart';
import 'package:monumento/resources/authentication/models/user_model.dart';
import 'package:monumento/ui/screens/home/home_screen.dart';
import 'package:monumento/ui/screens/signup/register_screen.dart';
import 'package:monumento/utilities/constants.dart';
import 'package:monumento/utilities/utils.dart';

import '../../../blocs/login_validation/login_validation_state.dart';
import '../profile_form/profile_form_screen.dart';

class LoginScreen extends StatefulWidget {
Expand All @@ -29,13 +32,15 @@ class _LoginScreenState extends State<LoginScreen> {

AuthenticationBloc _authenticationBloc;
LoginRegisterBloc _loginRegisterBloc;
LoginValidationBloc _loginValidationBloc;

@override
void initState() {
super.initState();
isseen = false;
_authenticationBloc = BlocProvider.of<AuthenticationBloc>(context);
_loginRegisterBloc = BlocProvider.of<LoginRegisterBloc>(context);
_loginValidationBloc = BlocProvider.of<LoginValidationBloc>(context);
}

Widget _buildEmailTF() {
Expand All @@ -52,9 +57,12 @@ class _LoginScreenState extends State<LoginScreen> {
decoration: kBoxDecorationStyle,
height: 60.0,
child: TextField(
//TODO: Email Validation

keyboardType: TextInputType.emailAddress,
controller: _emailController,
onChanged: (val){
_loginValidationBloc.add(LoginTextChangedEvent(_emailController.text, _passwordController.text));
},
style: TextStyle(
color: Colors.amber,
),
Expand Down Expand Up @@ -92,6 +100,9 @@ class _LoginScreenState extends State<LoginScreen> {
obscureText: !isseen,
keyboardType: TextInputType.visiblePassword,
controller: _passwordController,
onChanged: (val){
_loginValidationBloc.add(LoginTextChangedEvent(_emailController.text, _passwordController.text));
},
style: TextStyle(
color: Colors.amber,
),
Expand Down Expand Up @@ -131,7 +142,7 @@ class _LoginScreenState extends State<LoginScreen> {
onPressed: () => print('Forgot Password Button Pressed'),
child: Text(
'Forgot Password?',
style: kLabelStyleAmber,
style: kLabelStyle,
),
),
);
Expand Down Expand Up @@ -202,20 +213,18 @@ class _LoginScreenState extends State<LoginScreen> {
);
}


Widget _buildSocialBtn() {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 30.0),
child: GestureDetector(
onTap: () {}, // Image tapped
child: Image.asset(
'assets/google.png',
fit: BoxFit.cover, // Fixes border issues
width: 30.0,
height: 30.0,
),
)
);
padding: const EdgeInsets.symmetric(vertical: 30.0),
child: GestureDetector(
onTap: () {}, // Image tapped
child: Image.asset(
'assets/google.png',
fit: BoxFit.cover, // Fixes border issues
width: 30.0,
height: 30.0,
),
));
}

Widget _buildSignupBtn() {
Expand Down Expand Up @@ -300,6 +309,19 @@ class _LoginScreenState extends State<LoginScreen> {
width: 110.0,
),
SizedBox(height: 30.0),
BlocBuilder<LoginValidationBloc,
LoginValidationState>(
builder: (context, state) {
if (state is LoginValidationErrorState) {
return Text(state.errorMessage,
style: TextStyle(color: Colors.red));
}
else{
return Container();
}
},
),
SizedBox(height: 10.0),
Container(
width: double.infinity,
child: Text(
Expand Down
Loading