mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 10:57:55 +00:00
profile page
This commit is contained in:
@@ -45,6 +45,7 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
Future<void> saveName(SaveNameEvent event, Emitter<ProfileState> emit) async {
|
||||
if (_validateInputs()) return;
|
||||
try {
|
||||
|
||||
add(const ChangeNameEvent(value: false));
|
||||
isSaving = true;
|
||||
emit(LoadingInitialState());
|
||||
@@ -55,7 +56,7 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
var response = await ProfileApi.saveName(firstName: firstName, lastName: lastName);
|
||||
add(InitialProfileEvent());
|
||||
await HomeCubit.getInstance().fetchUserInfo();
|
||||
Navigator.of(event.context).pop(true);
|
||||
// Navigator.of(event.context).pop(true);
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
emit(SaveState());
|
||||
} catch (_) {
|
||||
@@ -229,14 +230,45 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
|
||||
|
||||
|
||||
|
||||
bool _validateInputs() {
|
||||
if (nameController.text.length < 2) {
|
||||
CustomSnackBar.displaySnackBar('Name Must More than 2 ');
|
||||
final nameError = fullNameValidator(nameController.text);
|
||||
if (nameError != null) {
|
||||
CustomSnackBar.displaySnackBar(nameError);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
String? fullNameValidator(String? value) {
|
||||
if (value == null) return 'Full name is required';
|
||||
|
||||
final withoutExtraSpaces = value.replaceAll(RegExp(r"\s+"), ' ').trim();
|
||||
|
||||
if (withoutExtraSpaces.length < 2 || withoutExtraSpaces.length > 30) {
|
||||
return 'Full name must be between 2 and 30 characters long';
|
||||
}
|
||||
|
||||
// Test if it contains anything but alphanumeric spaces and single quote
|
||||
|
||||
if (RegExp(r"/[^ a-zA-Z0-9-\']/").hasMatch(withoutExtraSpaces)) {
|
||||
return 'Only alphanumeric characters, space, dash and single quote are allowed';
|
||||
}
|
||||
|
||||
final parts = withoutExtraSpaces.split(' ');
|
||||
|
||||
if (parts.length < 2) return 'Full name must contain first and last names';
|
||||
|
||||
if (parts.length > 3) return 'Full name can at most contain 3 parts';
|
||||
|
||||
if (parts.any((part) => part.length < 2 || part.length > 30)) {
|
||||
return 'Full name parts must be between 2 and 30 characters long';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Future<bool> _requestPermission() async {
|
||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
if (Platform.isAndroid ) {
|
||||
|
||||
Reference in New Issue
Block a user