Bug fixes

This commit is contained in:
Abdullah Alassaf
2024-10-09 21:29:20 +03:00
11 changed files with 245 additions and 297 deletions
+3 -14
View File
@@ -108,20 +108,9 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
}
} on DioException catch (e) {
final errorData = e.response!.data;
String errorMessage = errorData['message'];
if (errorMessage == 'this email is not registered') {
validate = 'Invalid Credentials!';
emit(AuthInitialState());
} else if (errorMessage == "You entered wrong otp") {
forgetValidate = 'Wrong one time password.';
emit(AuthInitialState());
} else if (errorMessage == "OTP expired") {
forgetValidate = 'One time password has been expired.';
emit(AuthInitialState());
} else {
validate = '';
emit(AuthInitialState());
}
String errorMessage = errorData['error']['message'] ?? 'something went wrong';
validate = errorMessage;
emit(AuthInitialState());
}
}
+86 -130
View File
@@ -48,8 +48,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
late ScrollController _scrollController;
_scrollController = ScrollController();
void _scrollToCenter() {
final double middlePosition =
_scrollController.position.maxScrollExtent / 2;
final double middlePosition = _scrollController.position.maxScrollExtent / 2;
_scrollController.animateTo(
middlePosition,
duration: const Duration(seconds: 1),
@@ -66,8 +65,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
second: Center(
child: Stack(
children: [
if (state is AuthLoading)
const Center(child: CircularProgressIndicator()),
if (state is AuthLoading) const Center(child: CircularProgressIndicator()),
ListView(
shrinkWrap: true,
controller: _scrollController,
@@ -97,21 +95,16 @@ class ForgetPasswordWebPage extends StatelessWidget {
child: Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.1),
borderRadius:
const BorderRadius.all(Radius.circular(30)),
border: Border.all(
color:
ColorsManager.graysColor.withOpacity(0.2)),
borderRadius: const BorderRadius.all(Radius.circular(30)),
border: Border.all(color: ColorsManager.graysColor.withOpacity(0.2)),
),
child: Form(
key: forgetBloc.forgetFormKey,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: size.width * 0.02,
vertical: size.width * 0.003),
horizontal: size.width * 0.02, vertical: size.width * 0.003),
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 10),
@@ -128,66 +121,55 @@ class ForgetPasswordWebPage extends StatelessWidget {
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400),
.copyWith(fontSize: 14, fontWeight: FontWeight.w400),
),
const SizedBox(height: 10),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(height: 10),
Form(
key: forgetBloc.forgetRegionKey,
child: SizedBox(
child: _buildDropdownField(
context, forgetBloc, size)))
Form(
key: forgetBloc.forgetRegionKey,
child: SizedBox(
child:
_buildDropdownField(context, forgetBloc, size)))
],
),
const SizedBox(height: 20),
Form(
key: forgetBloc.forgetEmailKey,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"Account",
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontSize: 14,
fontWeight:
FontWeight.w400),
style: Theme.of(context).textTheme.bodySmall!.copyWith(
fontSize: 14, fontWeight: FontWeight.w400),
),
const SizedBox(height: 10),
SizedBox(
child: TextFormField(
controller: forgetBloc.forgetEmailController,
validator: forgetBloc.validateEmail,
decoration:
textBoxDecoration()!.copyWith(
decoration: textBoxDecoration()!.copyWith(
hintText: 'Enter your email',
hintStyle: Theme.of(context)
.textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400),
.textTheme
.bodySmall!
.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400),
),
style: const TextStyle(
color: Colors.black),
style: const TextStyle(color: Colors.black),
),
),
],
)),
const SizedBox(height: 20.0),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
@@ -195,35 +177,40 @@ class ForgetPasswordWebPage extends StatelessWidget {
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400),
.copyWith(fontSize: 14, fontWeight: FontWeight.w400),
),
const SizedBox(height: 10),
SizedBox(
child: TextFormField(
validator: forgetBloc.validateCode,
keyboardType:
TextInputType.visiblePassword,
keyboardType: TextInputType.visiblePassword,
controller: forgetBloc.forgetOtp,
decoration:
textBoxDecoration()!.copyWith(
decoration: textBoxDecoration()!.copyWith(
hintText: 'Enter Code',
hintStyle: Theme.of(context).textTheme
.bodySmall!.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400),
hintStyle: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400),
suffixIcon: SizedBox(
width: 100,
child: Center(
child: InkWell(
onTap: state is TimerState &&
!state.isButtonEnabled &&
state.remainingTime != 1
!state.isButtonEnabled &&
state.remainingTime != 1
? null
: () {
if (forgetBloc.forgetEmailKey.currentState!.validate()||forgetBloc.forgetRegionKey.currentState!.validate()) {
if(forgetBloc.forgetRegionKey.currentState!.validate()){
if (forgetBloc
.forgetEmailKey.currentState!
.validate() ||
forgetBloc
.forgetRegionKey.currentState!
.validate()) {
if (forgetBloc
.forgetRegionKey.currentState!
.validate()) {
forgetBloc.add(StartTimerEvent());
}
}
@@ -231,28 +218,23 @@ class ForgetPasswordWebPage extends StatelessWidget {
child: Text(
'Get Code ${state is TimerState && !state.isButtonEnabled && state.remainingTime != 1 ? "(${forgetBloc.formattedTime(state.remainingTime)}) " : ""}',
style: TextStyle(
color: state
is TimerState &&
!state
.isButtonEnabled
color: state is TimerState &&
!state.isButtonEnabled
? Colors.grey
: ColorsManager
.btnColor,
: ColorsManager.btnColor,
),
),
),
),
),
),
style: const TextStyle(
color: Colors.black),
style: const TextStyle(color: Colors.black),
),
),
if (forgetBloc.forgetValidate !=
'') // Check if there is a validation message
Padding(
padding:
const EdgeInsets.only(top: 8.0),
padding: const EdgeInsets.only(top: 8.0),
child: Text(
forgetBloc.forgetValidate,
style: const TextStyle(
@@ -265,8 +247,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
),
const SizedBox(height: 20.0),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
@@ -274,35 +255,26 @@ class ForgetPasswordWebPage extends StatelessWidget {
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400),
.copyWith(fontSize: 14, fontWeight: FontWeight.w400),
),
const SizedBox(height: 10),
SizedBox(
child: TextFormField(
obscureText: forgetBloc.obscureText,
keyboardType:
TextInputType.visiblePassword,
validator:
forgetBloc.passwordValidator,
controller: forgetBloc
.forgetPasswordController,
decoration:
textBoxDecoration()!.copyWith(
keyboardType: TextInputType.visiblePassword,
validator: forgetBloc.passwordValidator,
controller: forgetBloc.forgetPasswordController,
decoration: textBoxDecoration()!.copyWith(
suffixIcon: IconButton(
onPressed: () {
forgetBloc.add(
PasswordVisibleEvent(
newValue: forgetBloc
.obscureText));
forgetBloc.add(PasswordVisibleEvent(
newValue: forgetBloc.obscureText));
},
icon: SizedBox(
child: SvgPicture.asset(
forgetBloc.obscureText
? Assets.visiblePassword
: Assets
.invisiblePassword,
: Assets.invisiblePassword,
height: 15,
width: 15,
),
@@ -313,13 +285,10 @@ class ForgetPasswordWebPage extends StatelessWidget {
.textTheme
.bodySmall!
.copyWith(
color:
ColorsManager.grayColor,
fontWeight:
FontWeight.w400),
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400),
),
style: const TextStyle(
color: Colors.black),
style: const TextStyle(color: Colors.black),
),
),
],
@@ -329,21 +298,22 @@ class ForgetPasswordWebPage extends StatelessWidget {
),
const SizedBox(height: 20.0),
Row(
crossAxisAlignment:
CrossAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: size.width * 0.2,
child: DefaultButton(
backgroundColor:
ColorsManager.btnColor,
backgroundColor: ColorsManager.btnColor,
child: const Text('Submit'),
onPressed: () {
if (forgetBloc.forgetFormKey.currentState!.validate() ||
forgetBloc.forgetEmailKey.currentState!.validate() ) {
if( forgetBloc.forgetEmailKey.currentState!.validate()
&&forgetBloc.forgetFormKey.currentState!.validate() ){
forgetBloc.forgetEmailKey.currentState!
.validate()) {
if (forgetBloc.forgetEmailKey.currentState!
.validate() &&
forgetBloc.forgetFormKey.currentState!
.validate()) {
forgetBloc.add(ChangePasswordEvent());
}
}
@@ -358,8 +328,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
child: Text(
forgetBloc.validate,
style: const TextStyle(
fontWeight: FontWeight.w700,
color: ColorsManager.red),
fontWeight: FontWeight.w700, color: ColorsManager.red),
),
),
),
@@ -372,8 +341,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
children: [
const Text(
"Do you have an account? ",
style:
TextStyle(color: Colors.white),
style: TextStyle(color: Colors.white),
),
InkWell(
onTap: () {
@@ -407,8 +375,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
));
}
Widget _buildDropdownField(
BuildContext context, AuthBloc loginBloc, Size size) {
Widget _buildDropdownField(BuildContext context, AuthBloc loginBloc, Size size) {
final TextEditingController textEditingController = TextEditingController();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -434,13 +401,10 @@ class ForgetPasswordWebPage extends StatelessWidget {
builder: (FormFieldState<String> field) {
return InputDecorator(
decoration: InputDecoration(
contentPadding:
const EdgeInsets.symmetric(horizontal: 2, vertical: 10),
contentPadding: const EdgeInsets.symmetric(horizontal: 2, vertical: 10),
errorText: field.errorText,
filled:
true, // Ensure the dropdown is filled with the background color
fillColor: ColorsManager
.boxColor, // Match the dropdown container color
filled: true, // Ensure the dropdown is filled with the background color
fillColor: ColorsManager.boxColor, // Match the dropdown container color
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
@@ -451,22 +415,20 @@ class ForgetPasswordWebPage extends StatelessWidget {
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color:
field.hasError ? Colors.red : ColorsManager.grayColor,
color: field.hasError ? Colors.red : ColorsManager.grayColor,
width: 1.5,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color:
field.hasError ? Colors.red : ColorsManager.grayColor,
color: field.hasError ? Colors.red : ColorsManager.grayColor,
width: 1.5,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
borderSide: const BorderSide(
color: Colors.red,
width: 1.5,
),
@@ -488,24 +450,22 @@ class ForgetPasswordWebPage extends StatelessWidget {
value: region.id,
child: Text(
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400,
),
fontSize: 14,
fontWeight: FontWeight.w400,
),
region.name,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
);
}).toList(),
value: loginBloc.regionList!
.any((region) => region.id == loginBloc.regionUuid)
value: loginBloc.regionList!.any((region) => region.id == loginBloc.regionUuid)
? loginBloc.regionUuid
: null,
onChanged: (String? value) {
if (value != null) {
loginBloc.add(SelectRegionEvent(val: value));
field.didChange(
value); // Notify the form field of the change
field.didChange(value); // Notify the form field of the change
}
},
buttonStyleData: const ButtonStyleData(
@@ -529,8 +489,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
searchInnerWidgetHeight: 50,
searchInnerWidget: Container(
height: 50,
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 4),
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: TextFormField(
style: const TextStyle(color: Colors.black),
controller: textEditingController,
@@ -544,8 +503,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
),
),
searchMatchFn: (item, searchValue) {
final regionName =
(item.child as Text).data?.toLowerCase() ?? '';
final regionName = (item.child as Text).data?.toLowerCase() ?? '';
final search = searchValue.toLowerCase().trim();
return regionName.contains(search);
},
@@ -564,6 +522,4 @@ class ForgetPasswordWebPage extends StatelessWidget {
],
);
}
}
+32 -41
View File
@@ -24,8 +24,7 @@ class LoginWebPage extends StatefulWidget {
State<LoginWebPage> createState() => _LoginWebPageState();
}
class _LoginWebPageState extends State<LoginWebPage>
with HelperResponsiveLayout {
class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout {
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -60,8 +59,7 @@ class _LoginWebPageState extends State<LoginWebPage>
_scrollController = ScrollController();
void _scrollToCenter() {
final double middlePosition =
_scrollController.position.maxScrollExtent / 2;
final double middlePosition = _scrollController.position.maxScrollExtent / 2;
_scrollController.animateTo(
middlePosition,
duration: const Duration(seconds: 1),
@@ -123,8 +121,7 @@ class _LoginWebPageState extends State<LoginWebPage>
const Spacer(),
Expanded(
flex: 2,
child: _buildLoginFormFields(
context, loginBloc, size),
child: _buildLoginFormFields(context, loginBloc, size),
),
const Spacer(),
],
@@ -135,14 +132,12 @@ class _LoginWebPageState extends State<LoginWebPage>
),
),
),
if (state is AuthLoading)
const Center(child: CircularProgressIndicator())
if (state is AuthLoading) const Center(child: CircularProgressIndicator())
],
);
}
Widget _buildLoginFormFields(
BuildContext context, AuthBloc loginBloc, Size size) {
Widget _buildLoginFormFields(BuildContext context, AuthBloc loginBloc, Size size) {
return Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.1),
@@ -152,8 +147,8 @@ class _LoginWebPageState extends State<LoginWebPage>
child: Form(
key: loginBloc.loginFormKey,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: size.width * 0.02, vertical: size.width * 0.003),
padding:
EdgeInsets.symmetric(horizontal: size.width * 0.02, vertical: size.width * 0.003),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -181,9 +176,7 @@ class _LoginWebPageState extends State<LoginWebPage>
);
}
Widget _buildDropdownField(
BuildContext context, AuthBloc loginBloc, Size size) {
Widget _buildDropdownField(BuildContext context, AuthBloc loginBloc, Size size) {
final TextEditingController textEditingController = TextEditingController();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -192,9 +185,9 @@ class _LoginWebPageState extends State<LoginWebPage>
Text(
"Country/Region",
style: Theme.of(context).textTheme.bodySmall!.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400,
),
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
const SizedBox(height: 10),
Container(
@@ -211,9 +204,9 @@ class _LoginWebPageState extends State<LoginWebPage>
hint: Text(
'Select your region/country',
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400,
),
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400,
),
overflow: TextOverflow.ellipsis,
),
items: loginBloc.regionList!.map((RegionModel region) {
@@ -227,7 +220,8 @@ class _LoginWebPageState extends State<LoginWebPage>
);
}).toList(),
value: loginBloc.regionList!.any(
(region) => region.id == loginBloc.regionUuid,)
(region) => region.id == loginBloc.regionUuid,
)
? loginBloc.regionUuid
: null,
onChanged: (String? value) {
@@ -286,7 +280,6 @@ class _LoginWebPageState extends State<LoginWebPage>
);
}
Widget _buildEmailField(BuildContext context, AuthBloc loginBloc) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -310,9 +303,10 @@ class _LoginWebPageState extends State<LoginWebPage>
decoration: textBoxDecoration()!.copyWith(
errorStyle: const TextStyle(height: 0),
hintText: 'Enter your email address',
hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400)),
hintStyle: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: ColorsManager.grayColor, fontWeight: FontWeight.w400)),
style: const TextStyle(color: Colors.black),
),
),
@@ -344,18 +338,17 @@ class _LoginWebPageState extends State<LoginWebPage>
controller: loginBloc.loginPasswordController,
decoration: textBoxDecoration()!.copyWith(
hintText: 'At least 8 characters',
hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor, fontWeight: FontWeight.w400),
hintStyle: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: ColorsManager.grayColor, fontWeight: FontWeight.w400),
suffixIcon: IconButton(
onPressed: () {
loginBloc.add(
PasswordVisibleEvent(newValue: loginBloc.obscureText));
loginBloc.add(PasswordVisibleEvent(newValue: loginBloc.obscureText));
},
icon: SizedBox(
child: SvgPicture.asset(
loginBloc.obscureText
? Assets.visiblePassword
: Assets.invisiblePassword,
loginBloc.obscureText ? Assets.visiblePassword : Assets.invisiblePassword,
height: 15,
width: 15,
),
@@ -383,10 +376,10 @@ class _LoginWebPageState extends State<LoginWebPage>
},
child: Text(
"Forgot Password?",
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.w400),
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.black, fontSize: 14, fontWeight: FontWeight.w400),
),
),
],
@@ -450,8 +443,7 @@ class _LoginWebPageState extends State<LoginWebPage>
);
}
Widget _buildSignInButton(
BuildContext context, AuthBloc loginBloc, Size size) {
Widget _buildSignInButton(BuildContext context, AuthBloc loginBloc, Size size) {
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
@@ -492,8 +484,7 @@ class _LoginWebPageState extends State<LoginWebPage>
SizedBox(
child: Text(
loginBloc.validate,
style: const TextStyle(
fontWeight: FontWeight.w700, color: ColorsManager.red),
style: const TextStyle(fontWeight: FontWeight.w700, color: ColorsManager.red),
),
)
],