mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 00:47:56 +00:00
Fixed design issues, added updated read me file
This commit is contained in:
@@ -23,13 +23,12 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
String timeZoneSelected = '';
|
||||
String regionSelected = '';
|
||||
final TextEditingController searchController = TextEditingController();
|
||||
final TextEditingController nameController = TextEditingController(text: '${HomeCubit.user!.firstName} ${HomeCubit.user!.lastName}');
|
||||
|
||||
final TextEditingController nameController =
|
||||
TextEditingController(text: '${HomeCubit.user!.firstName} ${HomeCubit.user!.lastName}');
|
||||
|
||||
List<RegionModel> allRegions = [];
|
||||
List<TimeZone> allTimeZone = [];
|
||||
|
||||
|
||||
ProfileBloc() : super(InitialState()) {
|
||||
on<InitialProfileEvent>(_fetchUserInfo);
|
||||
on<TimeZoneInitialEvent>(_fetchTimeZone);
|
||||
@@ -53,7 +52,7 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
final nameParts = fullName.split(' ');
|
||||
final firstName = nameParts[0];
|
||||
final lastName = nameParts.length > 1 ? nameParts[1] : '';
|
||||
var response = await ProfileApi.saveName(firstName: firstName, lastName: lastName);
|
||||
await ProfileApi.saveName(firstName: firstName, lastName: lastName);
|
||||
add(InitialProfileEvent());
|
||||
await HomeCubit.getInstance().fetchUserInfo();
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
@@ -72,7 +71,7 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
focusNode.requestFocus();
|
||||
});
|
||||
}else {
|
||||
} else {
|
||||
focusNode.unfocus();
|
||||
}
|
||||
emit(NameEditingState(editName: editName));
|
||||
@@ -116,7 +115,7 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
Future selectRegion(SelectRegionEvent event, Emitter<ProfileState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
await ProfileApi.saveRegion(regionUuid:event.val );
|
||||
await ProfileApi.saveRegion(regionUuid: event.val);
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
emit(SaveState());
|
||||
} catch (e) {
|
||||
@@ -125,7 +124,6 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> searchRegion(SearchRegionEvent event, Emitter<ProfileState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
final query = event.query.toLowerCase();
|
||||
@@ -158,7 +156,6 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _fetchRegion(RegionInitialEvent event, Emitter<ProfileState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
@@ -170,36 +167,37 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
}
|
||||
|
||||
Future<void> _selectImage(SelectImageEvent event, Emitter<ProfileState> emit) async {
|
||||
if (await _requestPermission()) {
|
||||
emit(ChangeImageState());
|
||||
final pickedFile = await _picker.pickImage(source: ImageSource.gallery);
|
||||
if (pickedFile != null) {
|
||||
image = File(pickedFile.path);
|
||||
final bytes = image!.readAsBytesSync().lengthInBytes;
|
||||
final kb = bytes / 1024;
|
||||
final mb = kb / 1024;
|
||||
if(mb>1){
|
||||
image=null;
|
||||
CustomSnackBar.displaySnackBar('Image size must be 1 MB or less');
|
||||
}else{
|
||||
await _saveImage();
|
||||
try {
|
||||
if (await _requestPermission()) {
|
||||
emit(ChangeImageState());
|
||||
final pickedFile = await _picker.pickImage(source: ImageSource.gallery);
|
||||
if (pickedFile != null) {
|
||||
image = File(pickedFile.path);
|
||||
final bytes = image!.readAsBytesSync().lengthInBytes;
|
||||
final kb = bytes / 1024;
|
||||
final mb = kb / 1024;
|
||||
if (mb > 1) {
|
||||
image = null;
|
||||
CustomSnackBar.displaySnackBar('Image size must be 1 MB or less');
|
||||
} else {
|
||||
emit(LoadingInitialState());
|
||||
await _saveImage();
|
||||
emit(ImageSelectedState());
|
||||
}
|
||||
}
|
||||
emit(ImageSelectedState());
|
||||
} else {
|
||||
print('No image selected.');
|
||||
_showPermissionDeniedDialog(event.context);
|
||||
}
|
||||
emit(ImageSelectedState());
|
||||
} else {
|
||||
_showPermissionDeniedDialog(event.context);
|
||||
} catch (_) {
|
||||
emit(const FailedState(errorMessage: 'Something went wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _saveImage() async {
|
||||
emit(LoadingInitialState());
|
||||
List<int> imageBytes = image!.readAsBytesSync();
|
||||
String base64Image = base64Encode(imageBytes);
|
||||
print(base64Image);
|
||||
var response = await ProfileApi.saveImage(base64Image);
|
||||
emit(ImageSelectedState());
|
||||
await ProfileApi.saveImage(base64Image);
|
||||
}
|
||||
|
||||
void _showPermissionDeniedDialog(BuildContext context) {
|
||||
@@ -229,9 +227,6 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool _validateInputs() {
|
||||
final nameError = fullNameValidator(nameController.text);
|
||||
if (nameError != null) {
|
||||
@@ -241,7 +236,6 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
String? fullNameValidator(String? value) {
|
||||
if (value == null) return 'Full name is required';
|
||||
final withoutExtraSpaces = value.replaceAll(RegExp(r"\s+"), ' ').trim();
|
||||
@@ -261,13 +255,12 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Future<bool> _requestPermission() async {
|
||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
if (Platform.isAndroid ) {
|
||||
if (Platform.isAndroid) {
|
||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
PermissionStatus status = await Permission.photos.status;
|
||||
if(androidInfo.version.sdkInt<33){
|
||||
if (androidInfo.version.sdkInt < 33) {
|
||||
if (status.isDenied) {
|
||||
PermissionStatus status = await Permission.storage.request();
|
||||
if (status.isGranted) {
|
||||
@@ -276,7 +269,7 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
if (status.isGranted) {
|
||||
return true;
|
||||
} else if (status.isDenied) {
|
||||
@@ -301,5 +294,4 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user