You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
288 lines
9.6 KiB
Dart
288 lines
9.6 KiB
Dart
import 'package:car_customer_app/api/client/user_api_client.dart';
|
|
import 'package:car_customer_app/classes/utils.dart';
|
|
import 'package:car_customer_app/config/routes.dart';
|
|
import 'package:car_customer_app/generated/locale_keys.g.dart';
|
|
import 'package:car_customer_app/models/m_response.dart';
|
|
import 'package:car_customer_app/models/user/basic_otp.dart';
|
|
import 'package:car_customer_app/models/user/register_user.dart';
|
|
import 'package:car_customer_app/utils/navigator.dart';
|
|
import 'package:car_customer_app/utils/utils.dart';
|
|
import 'package:car_customer_app/widgets/app_bar.dart';
|
|
import 'package:car_customer_app/widgets/dialog/dialogs.dart';
|
|
import 'package:car_customer_app/widgets/dialog/message_dialog.dart';
|
|
import 'package:car_customer_app/widgets/dialog/otp_dialog.dart';
|
|
import 'package:car_customer_app/widgets/show_fill_button.dart';
|
|
import 'package:car_customer_app/extensions/widget_extensions.dart';
|
|
import 'package:car_customer_app/extensions/int_extensions.dart';
|
|
import 'package:car_customer_app/extensions/string_extensions.dart';
|
|
import 'package:car_customer_app/widgets/txt_field.dart';
|
|
import 'package:easy_localization/src/public_ext.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_password_strength/flutter_password_strength.dart';
|
|
|
|
class CompleteProfilePage extends StatefulWidget {
|
|
RegisterUser user;
|
|
|
|
CompleteProfilePage(this.user);
|
|
|
|
@override
|
|
State<CompleteProfilePage> createState() => _CompleteProfilePageState();
|
|
}
|
|
|
|
class _CompleteProfilePageState extends State<CompleteProfilePage> {
|
|
String? firstName = "",
|
|
lastName = "",
|
|
email = "",
|
|
confirmPassword = "";
|
|
late String password = "";
|
|
bool isChecked = false;
|
|
|
|
double _strength = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: appBar(title: LocaleKeys.signUp.tr()),
|
|
body: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
child: SingleChildScrollView(
|
|
child: Padding(
|
|
padding: EdgeInsets.all(20),
|
|
child: Column(
|
|
children: [
|
|
LocaleKeys.completeProfile.tr().toText24(),
|
|
12.height,
|
|
|
|
TxtField(
|
|
hint: LocaleKeys.firstName.tr(),
|
|
value: firstName,
|
|
onChanged: (v) {
|
|
firstName = v;
|
|
},
|
|
),
|
|
12.height,
|
|
TxtField(
|
|
hint: LocaleKeys.surname.tr(),
|
|
value: lastName,
|
|
onChanged: (v) {
|
|
lastName = v;
|
|
},
|
|
),
|
|
12.height,
|
|
TxtField(
|
|
hint: LocaleKeys.email.tr(),
|
|
value: email,
|
|
// isButtonEnable: email!.length > 0 ? true : false,
|
|
buttonTitle: LocaleKeys.verify.tr(),
|
|
onChanged: (v) {
|
|
email = v;
|
|
},
|
|
),
|
|
12.height,
|
|
TxtField(
|
|
hint: LocaleKeys.createPass.tr(),
|
|
isPasswordEnabled: true,
|
|
maxLines: 1,
|
|
value: password,
|
|
onChanged: (value) => _checkPassword(value),
|
|
// onChanged: (v) {
|
|
// password = v;
|
|
// },
|
|
),
|
|
password!.isNotEmpty ? 12.height : 0.height,
|
|
// The strength indicator bar
|
|
password!.isNotEmpty ? LinearProgressIndicator(
|
|
value: _strength,
|
|
backgroundColor: Colors.grey[300],
|
|
color: _strength <= 1 / 4
|
|
? Colors.yellow
|
|
: _strength == 2 / 4
|
|
? Colors.orange
|
|
: _strength == 3 / 4
|
|
? Colors.deepOrange
|
|
: Colors.red,
|
|
minHeight: 4,
|
|
): Container(),
|
|
// The message about the strength of the entered password
|
|
Text(
|
|
_displayText,
|
|
style: const TextStyle(fontSize: 12),
|
|
),
|
|
12.height,
|
|
TxtField(
|
|
hint: LocaleKeys.confirmPass.tr(),
|
|
isPasswordEnabled: true,
|
|
maxLines: 1,
|
|
value: confirmPassword,
|
|
onChanged: (v) {
|
|
confirmPassword = v;
|
|
},
|
|
),
|
|
// 12.height,
|
|
// TxtField(
|
|
// hint: "Phone Number",
|
|
// ),
|
|
50.height,
|
|
Row(
|
|
children: [
|
|
buildCheckbox(),
|
|
LocaleKeys.termsOfService.tr().toText12(),
|
|
],
|
|
),
|
|
16.height,
|
|
ShowFillButton(
|
|
title: LocaleKeys.continu.tr(),
|
|
width: double.infinity,
|
|
onPressed: () {
|
|
if (validation()) performCompleteProfile();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget buildCheckbox() =>
|
|
Checkbox(
|
|
value: isChecked,
|
|
activeColor: Colors.blue,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
isChecked = value!;
|
|
});
|
|
},
|
|
);
|
|
|
|
// Future<void> performCompleteProfile() async {
|
|
// if(validateStructure(password??"")){
|
|
// if (password == confirmPassword) {
|
|
// print(widget.user.data!.userId??"userId");
|
|
// Utils.showLoading(context);
|
|
// RegisterUser user = await UserApiClent().basicComplete(widget.user.data?.userId ?? "", firstName!, lastName!, email!, password!);
|
|
// Utils.hideLoading(context);
|
|
// if (user.messageStatus == 1) {
|
|
// Utils.showToast( "Successfully registered, Please login once");
|
|
// pop(context);
|
|
// // pop(context);
|
|
// // navigateReplaceWithName(context, AppRoutes.dashboard,arguments: user);
|
|
// } else {
|
|
// Utils.showToast(user.message ?? "");
|
|
// }
|
|
// } else {
|
|
// Utils.showToast("Please enter same password");
|
|
// }
|
|
// }else{
|
|
// Utils.showToast("Password Should contains character, Number, Capital and small letters");
|
|
// }
|
|
//
|
|
// }
|
|
|
|
Future<void> performCompleteProfile() async {
|
|
if (validateStructure(password ?? "")) {
|
|
if (password == confirmPassword) {
|
|
print(widget.user.data!.userInfo!.userId ?? "userId");
|
|
Utils.showLoading(context);
|
|
RegisterUser user = await UserApiClent().basicComplete(widget.user.data?.userInfo!.userId ?? "", firstName!, lastName!, email!, password!);
|
|
Utils.hideLoading(context);
|
|
if (user.messageStatus == 1) {
|
|
Utils.showToast(LocaleKeys.successfullyRegistered.tr());
|
|
//("Successfully Registered, Please login once");
|
|
pop(context);
|
|
// navigateReplaceWithName(context, AppRoutes.dashboard,arguments: user);
|
|
} else {
|
|
Utils.showToast(user.message ?? "");
|
|
}
|
|
} else {
|
|
Utils.showToast(LocaleKeys.pleaseEnterSamePassword.tr());
|
|
//("Please enter same password");
|
|
}
|
|
} else {
|
|
Utils.showToast(LocaleKeys.passwordShouldContains.tr());
|
|
//("Password Should contains Character, Number, Capital and small letters");
|
|
}
|
|
}
|
|
|
|
bool validateStructure(String value) {
|
|
String pattern = r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{6,}$';
|
|
RegExp regExp = new RegExp(pattern);
|
|
return regExp.hasMatch(value);
|
|
}
|
|
|
|
|
|
bool isEmail(String em) {
|
|
String p = r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
|
|
RegExp regExp = new RegExp(p);
|
|
return regExp.hasMatch(em);
|
|
}
|
|
|
|
bool validation() {
|
|
bool isValid = true;
|
|
if (firstName!.isEmpty) {
|
|
Utils.showToast(LocaleKeys.firstNameMandatory.tr());
|
|
//("First name is mandatory");
|
|
isValid = false;
|
|
} else if (lastName!.isEmpty) {
|
|
Utils.showToast(LocaleKeys.surnameNameMandatory.tr());
|
|
//("Surname is mandatory");
|
|
isValid = false;
|
|
} else if (email!.isNotEmpty) {
|
|
if (!isEmail(email!)) {
|
|
Utils.showToast(LocaleKeys.enterValidEmail.tr());
|
|
//("Enter Valid Email");
|
|
isValid = false;
|
|
}
|
|
} else if (password!.isEmpty) {
|
|
Utils.showToast(LocaleKeys.passwordNameMandatory.tr());
|
|
//("Password is mandatory");
|
|
isValid = false;
|
|
} else if (!isChecked) {
|
|
Utils.showToast(LocaleKeys.pleaseAcceptTerms.tr());
|
|
//("Please accept terms");
|
|
isValid = false;
|
|
}
|
|
return isValid;
|
|
}
|
|
|
|
RegExp numReg = RegExp(r".*[0-9].*");
|
|
RegExp letterReg = RegExp(r".*[A-Za-z].*");
|
|
|
|
String _displayText = '';
|
|
|
|
void _checkPassword(String value) {
|
|
password = value.trim();
|
|
if (password!.length <= 6) {
|
|
setState(() {
|
|
_strength = 1 / 4;
|
|
_displayText = 'Your password is too short';
|
|
});
|
|
} else if (password!.length < 8) {
|
|
setState(() {
|
|
_strength = 2 / 4;
|
|
_displayText = 'Your password is acceptable but not strong';
|
|
});
|
|
} else {
|
|
if (!letterReg.hasMatch(password!) || !numReg.hasMatch(password!)) {
|
|
setState(() {
|
|
_strength = 3 / 4;
|
|
_displayText = 'Your password is strong';
|
|
});
|
|
} else {
|
|
setState(() {
|
|
_strength = 1;
|
|
_displayText = 'Your password is very strong';
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|