Skip to content

Commit a8abb67

Browse files
committed
rfac: refactor reset password ui
Signed-off-by: Aman <aman2@me.iitr.ac.in>
1 parent 1fd861a commit a8abb67

4 files changed

Lines changed: 144 additions & 123 deletions

File tree

lib/presentation/login/login_screen.dart

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,20 @@ class LoginScreen extends StatelessWidget {
100100
obscureText: !state.showPassword,
101101
suffix: IconButton(
102102
onPressed: () {
103-
BlocProvider.of<LoginBloc>(context).add(
104-
ToggleObscureCreatePassword(
105-
showPassword: !state.showPassword,
106-
showConfirmPassword:
107-
state.showConfirmPassword,
108-
),
109-
);
103+
context.read<LoginBloc>().add(
104+
ToggleObscureCreatePassword(
105+
showPassword: !state.showPassword,
106+
showConfirmPassword:
107+
state.showConfirmPassword,
108+
),
109+
);
110110
},
111-
icon: state.showPassword
112-
? const Icon(Icons.visibility,
113-
color: Color(0xFF757575))
114-
: const Icon(Icons.visibility_off,
115-
color: Color(0xFF757575)),
111+
icon: Icon(
112+
state.showPassword
113+
? Icons.visibility
114+
: Icons.visibility_off,
115+
color: const Color(0xFF757575),
116+
),
116117
),
117118
title: 'Set Password',
118119
),
@@ -123,19 +124,20 @@ class LoginScreen extends StatelessWidget {
123124
obscureText: !state.showConfirmPassword,
124125
suffix: IconButton(
125126
onPressed: () {
126-
BlocProvider.of<LoginBloc>(context).add(
127-
ToggleObscureCreatePassword(
128-
showPassword: state.showPassword,
129-
showConfirmPassword:
130-
!state.showConfirmPassword,
131-
),
132-
);
127+
context.read<LoginBloc>().add(
128+
ToggleObscureCreatePassword(
129+
showPassword: state.showPassword,
130+
showConfirmPassword:
131+
!state.showConfirmPassword,
132+
),
133+
);
133134
},
134-
icon: state.showConfirmPassword
135-
? const Icon(Icons.visibility,
136-
color: Color(0xFF757575))
137-
: const Icon(Icons.visibility_off,
138-
color: Color(0xFF757575)),
135+
icon: Icon(
136+
state.showConfirmPassword
137+
? Icons.visibility
138+
: Icons.visibility_off,
139+
color: const Color(0xFF757575),
140+
),
139141
),
140142
),
141143
SizedBox(
@@ -187,15 +189,17 @@ class LoginScreen extends StatelessWidget {
187189
suffix: state is EnterPassword
188190
? IconButton(
189191
onPressed: () {
190-
BlocProvider.of<LoginBloc>(context).add(
191-
ShowPasswordPressed(),
192-
);
192+
context
193+
.read<LoginBloc>()
194+
.add(ShowPasswordPressed());
193195
},
194-
icon: state.showPassword
195-
? const Icon(Icons.visibility,
196-
color: Color(0xFF757575))
197-
: const Icon(Icons.visibility_off,
198-
color: Color(0xFF757575)))
196+
icon: Icon(
197+
state.showPassword
198+
? Icons.visibility
199+
: Icons.visibility_off,
200+
color: const Color(0xFF757575),
201+
),
202+
)
199203
: const SizedBox(),
200204
),
201205
state is EnterPassword

lib/presentation/reset_password/bloc/reset_password_bloc.dart

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,40 @@ class ResetPasswordBloc extends Bloc<ResetPasswordEvent, ResetPasswordState> {
1919
on<ResetPasswordPressed>(_onResetPasswordPressed);
2020
on<ToggleObscureResetPassword>(_onToggleObscureResetPassword);
2121
}
22-
23-
FutureOr<void> _onResetPasswordPressed(event, emit) async {
24-
if (event.newPassword.length < 8) {
22+
FutureOr<void> _onResetPasswordPressed(
23+
ResetPasswordPressed event, Emitter<ResetPasswordState> emit) async {
24+
bool isValidated = true;
25+
if (event.oldPassword.isEmpty ||
26+
event.newPassword.isEmpty ||
27+
event.confirmPassword.isEmpty) {
2528
emit(
26-
ResetPassword(
29+
(state as ResetPassword).copyWith(
30+
error: 'All fields are required',
31+
),
32+
);
33+
isValidated = false;
34+
} else if (event.newPassword.length < 8) {
35+
emit(
36+
(state as ResetPassword).copyWith(
2737
error: 'Password must be at least 8 characters long',
28-
showOldPassword: (state as ResetPassword).showOldPassword,
29-
showNewPassword: (state as ResetPassword).showNewPassword,
30-
showConfirmPassword: (state as ResetPassword).showConfirmPassword,
3138
),
3239
);
33-
emit(ResetPassword(
34-
error: null,
35-
showOldPassword: (state as ResetPassword).showOldPassword,
36-
showNewPassword: (state as ResetPassword).showNewPassword,
37-
showConfirmPassword: (state as ResetPassword).showConfirmPassword,
38-
));
39-
return;
40-
}
41-
if (event.newPassword != event.confirmPassword) {
40+
isValidated = false;
41+
} else if (event.newPassword != event.confirmPassword) {
42+
emit(
43+
(state as ResetPassword).copyWith(error: 'Passwords do not match'),
44+
);
45+
isValidated = false;
46+
} else if (event.oldPassword == event.newPassword) {
4247
emit(
43-
ResetPassword(
44-
error: 'Passwords do not match',
45-
showOldPassword: (state as ResetPassword).showOldPassword,
46-
showNewPassword: (state as ResetPassword).showNewPassword,
47-
showConfirmPassword: (state as ResetPassword).showConfirmPassword,
48+
(state as ResetPassword).copyWith(
49+
error: 'New password cannot be same as old password',
4850
),
4951
);
52+
isValidated = false;
53+
}
54+
55+
if (!isValidated) {
5056
emit(ResetPassword(
5157
error: null,
5258
showOldPassword: (state as ResetPassword).showOldPassword,
@@ -55,6 +61,7 @@ class ResetPasswordBloc extends Bloc<ResetPasswordEvent, ResetPasswordState> {
5561
));
5662
return;
5763
}
64+
5865
emit(Loading());
5966
try {
6067
await userRepository.changePassword(
@@ -69,10 +76,12 @@ class ResetPasswordBloc extends Bloc<ResetPasswordEvent, ResetPasswordState> {
6976
showNewPassword: false,
7077
showConfirmPassword: false,
7178
));
79+
emit((state as ResetPassword).copyWith(error: null));
7280
}
7381
}
7482

75-
FutureOr<void> _onToggleObscureResetPassword(event, emit) async {
83+
FutureOr<void> _onToggleObscureResetPassword(ToggleObscureResetPassword event,
84+
Emitter<ResetPasswordState> emit) async {
7685
emit(
7786
(state as ResetPassword).copyWith(
7887
showOldPassword: event.showOldPassword,

lib/presentation/reset_password/reset_password_view.dart

Lines changed: 76 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,31 @@ class ResetPasswordScreen extends StatelessWidget {
2222
create: (context) => ResetPasswordBloc(userRepository: context.read()),
2323
child: Scaffold(
2424
backgroundColor: Colors.white,
25-
body: BlocConsumer<ResetPasswordBloc, ResetPasswordState>(
26-
listener: (context, state) {
27-
if (state is ResetPassword && state.error != null) {
28-
ScaffoldMessenger.of(context).showSnackBar(
29-
SnackBar(
30-
content: Text(state.error!),
31-
backgroundColor: Colors.red,
32-
),
33-
);
34-
}
35-
if (state is ResetPasswordSuccess) {
36-
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
37-
content: Text('Password reset successfully!'),
38-
backgroundColor: Colors.green,
39-
));
40-
context.router.pop();
41-
}
42-
},
43-
builder: (context, state) {
44-
if (state is ResetPassword) {
45-
return Column(
46-
children: [
47-
const ResetPasswordBanner(),
48-
Expanded(
49-
child: SingleChildScrollView(
25+
body: Column(
26+
children: [
27+
const ResetPasswordBanner(),
28+
Expanded(
29+
child: BlocConsumer<ResetPasswordBloc, ResetPasswordState>(
30+
listener: (context, state) {
31+
if (state is ResetPassword && state.error != null) {
32+
ScaffoldMessenger.of(context).showSnackBar(
33+
SnackBar(
34+
content: Text(state.error!),
35+
backgroundColor: Colors.red,
36+
),
37+
);
38+
}
39+
if (state is ResetPasswordSuccess) {
40+
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
41+
content: Text('Password reset successfully!'),
42+
backgroundColor: Colors.green,
43+
));
44+
context.router.pop();
45+
}
46+
},
47+
builder: (context, state) {
48+
if (state is ResetPassword) {
49+
return SingleChildScrollView(
5050
padding: 24.toHorizontalPadding,
5151
child: Column(
5252
mainAxisAlignment: MainAxisAlignment.start,
@@ -58,19 +58,21 @@ class ResetPasswordScreen extends StatelessWidget {
5858
obscureText: !state.showOldPassword,
5959
suffix: IconButton(
6060
onPressed: () {
61-
BlocProvider.of<ResetPasswordBloc>(context).add(
62-
ToggleObscureResetPassword(
63-
showOldPassword: !state.showOldPassword,
64-
showNewPassword: state.showNewPassword,
65-
showConfirmPassword:
66-
state.showConfirmPassword),
67-
);
61+
context.read<ResetPasswordBloc>().add(
62+
ToggleObscureResetPassword(
63+
showOldPassword: !state.showOldPassword,
64+
showNewPassword: state.showNewPassword,
65+
showConfirmPassword:
66+
state.showConfirmPassword,
67+
),
68+
);
6869
},
69-
icon: state.showOldPassword
70-
? const Icon(Icons.visibility,
71-
color: Color(0xFF757575))
72-
: const Icon(Icons.visibility_off,
73-
color: Color(0xFF757575)),
70+
icon: Icon(
71+
state.showOldPassword
72+
? Icons.visibility
73+
: Icons.visibility_off,
74+
color: const Color(0xFF757575),
75+
),
7476
),
7577
title: 'Enter your old password',
7678
),
@@ -81,19 +83,22 @@ class ResetPasswordScreen extends StatelessWidget {
8183
obscureText: !state.showNewPassword,
8284
suffix: IconButton(
8385
onPressed: () {
84-
BlocProvider.of<ResetPasswordBloc>(context).add(
85-
ToggleObscureResetPassword(
86-
showNewPassword: !state.showNewPassword,
87-
showOldPassword: state.showOldPassword,
88-
showConfirmPassword:
89-
state.showConfirmPassword),
90-
);
86+
context.read<ResetPasswordBloc>().add(
87+
ToggleObscureResetPassword(
88+
showNewPassword:
89+
!state.showNewPassword,
90+
showOldPassword:
91+
state.showOldPassword,
92+
showConfirmPassword:
93+
state.showConfirmPassword),
94+
);
9195
},
92-
icon: state.showNewPassword
93-
? const Icon(Icons.visibility,
94-
color: Color(0xFF757575))
95-
: const Icon(Icons.visibility_off,
96-
color: Color(0xFF757575)),
96+
icon: Icon(
97+
state.showNewPassword
98+
? Icons.visibility
99+
: Icons.visibility_off,
100+
color: const Color(0xFF757575),
101+
),
97102
),
98103
title: 'Enter your new password',
99104
),
@@ -104,19 +109,21 @@ class ResetPasswordScreen extends StatelessWidget {
104109
obscureText: !state.showConfirmPassword,
105110
suffix: IconButton(
106111
onPressed: () {
107-
BlocProvider.of<ResetPasswordBloc>(context).add(
108-
ToggleObscureResetPassword(
109-
showConfirmPassword:
110-
!state.showConfirmPassword,
111-
showOldPassword: state.showOldPassword,
112-
showNewPassword: state.showNewPassword),
113-
);
112+
context.read<ResetPasswordBloc>().add(
113+
ToggleObscureResetPassword(
114+
showConfirmPassword:
115+
!state.showConfirmPassword,
116+
showOldPassword: state.showOldPassword,
117+
showNewPassword: state.showNewPassword,
118+
),
119+
);
114120
},
115-
icon: state.showConfirmPassword
116-
? const Icon(Icons.visibility,
117-
color: Color(0xFF757575))
118-
: const Icon(Icons.visibility_off,
119-
color: Color(0xFF757575)),
121+
icon: Icon(
122+
state.showConfirmPassword
123+
? Icons.visibility
124+
: Icons.visibility_off,
125+
color: const Color(0xFF757575),
126+
),
120127
),
121128
title: 'Confirm your new password',
122129
),
@@ -135,13 +142,14 @@ class ResetPasswordScreen extends StatelessWidget {
135142
),
136143
],
137144
),
138-
),
139-
),
140-
],
141-
);
142-
}
143-
return const Center(child: LoadingIndicator());
144-
},
145+
);
146+
}
147+
148+
return const Center(child: LoadingIndicator());
149+
},
150+
),
151+
),
152+
],
145153
),
146154
),
147155
);

lib/presentation/week_menu/components/DayMenu/menu_card.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class FeedbackAndCouponWidget extends StatelessWidget {
3737
return Center(
3838
child: Container(
3939
height: 24.toAutoScaledHeight,
40-
width: 88.toAutoScaledWidth,
40+
width: 90.toAutoScaledWidth,
4141
padding: EdgeInsets.symmetric(horizontal: 8.toAutoScaledWidth),
4242
decoration: ShapeDecoration(
4343
color: AppTheme.white,

0 commit comments

Comments
 (0)