Merge branch with resolved conflicts - restructured features and added new modules
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_chicken/data/di/chicken_di.dart';
|
||||
import 'package:rasadyar_chicken/data/models/request/change_password/change_password_request_model.dart';
|
||||
import 'package:rasadyar_chicken/data/models/response/iran_province_city/iran_province_city_model.dart';
|
||||
import 'package:rasadyar_chicken/data/models/response/user_profile/user_profile.dart';
|
||||
import 'package:rasadyar_chicken/data/repositories/chicken/chicken_repository.dart';
|
||||
import 'package:rasadyar_chicken/features/common/data/model/request/change_password/change_password_request_model.dart';
|
||||
import 'package:rasadyar_chicken/features/common/data/model/response/iran_province_city/iran_province_city_model.dart';
|
||||
import 'package:rasadyar_chicken/features/common/data/model/response/user_profile/user_profile.dart';
|
||||
import 'package:rasadyar_chicken/features/common/data/repositories/common/common_repository.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
class ProfileLogic extends GetxController {
|
||||
ChickenRepository chickenRepository = diChicken.get<ChickenRepository>();
|
||||
CommonRepository commonRepository = diChicken.get<CommonRepository>();
|
||||
GService gService = Get.find<GService>();
|
||||
TokenStorageService tokenService = Get.find<TokenStorageService>();
|
||||
RxInt selectedInformationType = 0.obs;
|
||||
@@ -43,6 +43,8 @@ class ProfileLogic extends GetxController {
|
||||
RxBool isUserInformationOpen = true.obs;
|
||||
RxBool isUnitInformationOpen = false.obs;
|
||||
|
||||
ScrollController scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -79,11 +81,10 @@ class ProfileLogic extends GetxController {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Future<void> getUserProfile() async {
|
||||
userProfile.value = Resource.loading();
|
||||
await safeCall<UserProfile?>(
|
||||
call: () async => await chickenRepository.getUserProfile(
|
||||
call: () async => await commonRepository.getUserProfile(
|
||||
token: tokenService.accessToken.value!,
|
||||
),
|
||||
onSuccess: (result) {
|
||||
@@ -97,7 +98,7 @@ class ProfileLogic extends GetxController {
|
||||
|
||||
Future<void> getCites() async {
|
||||
await safeCall(
|
||||
call: () => chickenRepository.getCity(
|
||||
call: () => commonRepository.getCity(
|
||||
provinceName: selectedProvince.value?.name ?? '',
|
||||
),
|
||||
onSuccess: (result) {
|
||||
@@ -124,7 +125,7 @@ class ProfileLogic extends GetxController {
|
||||
);
|
||||
isOnLoading.value = true;
|
||||
await safeCall(
|
||||
call: () async => await chickenRepository.updateUserProfile(
|
||||
call: () async => await commonRepository.updateUserProfile(
|
||||
token: tokenService.accessToken.value!,
|
||||
userProfile: userProfile,
|
||||
),
|
||||
@@ -145,7 +146,7 @@ class ProfileLogic extends GetxController {
|
||||
);
|
||||
|
||||
await safeCall(
|
||||
call: () async => await chickenRepository.updatePassword(
|
||||
call: () async => await commonRepository.updatePassword(
|
||||
token: tokenService.accessToken.value!,
|
||||
model: model,
|
||||
),
|
||||
@@ -178,4 +179,79 @@ class ProfileLogic extends GetxController {
|
||||
|
||||
Get.offAllNamed(newRole);
|
||||
}
|
||||
|
||||
void scrollToSelectedItem(
|
||||
int index, {
|
||||
double chipWidth = 100,
|
||||
double spacing = 8,
|
||||
GlobalKey? itemKey,
|
||||
}) {
|
||||
if (!scrollController.hasClients) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_performScroll(index, chipWidth, spacing, itemKey);
|
||||
});
|
||||
} else {
|
||||
_performScroll(index, chipWidth, spacing, itemKey);
|
||||
}
|
||||
}
|
||||
|
||||
void _performScroll(
|
||||
int index,
|
||||
double chipWidth,
|
||||
double spacing,
|
||||
GlobalKey? itemKey,
|
||||
) {
|
||||
if (!scrollController.hasClients) return;
|
||||
|
||||
double targetOffset;
|
||||
|
||||
// If we have a GlobalKey, use it for precise positioning
|
||||
if (itemKey?.currentContext != null) {
|
||||
final RenderBox? renderBox =
|
||||
itemKey!.currentContext?.findRenderObject() as RenderBox?;
|
||||
if (renderBox != null) {
|
||||
final position = renderBox.localToGlobal(Offset.zero);
|
||||
final scrollPosition = scrollController.position;
|
||||
final viewportWidth = scrollPosition.viewportDimension;
|
||||
final chipWidth = renderBox.size.width;
|
||||
|
||||
// Get the scroll position of the item
|
||||
final itemScrollPosition = position.dx - scrollPosition.pixels;
|
||||
// Center the item
|
||||
targetOffset =
|
||||
scrollPosition.pixels +
|
||||
itemScrollPosition -
|
||||
(viewportWidth / 2) +
|
||||
(chipWidth / 2);
|
||||
} else {
|
||||
// Fallback to estimated position
|
||||
targetOffset = _calculateEstimatedPosition(index, chipWidth, spacing);
|
||||
}
|
||||
} else {
|
||||
// Use estimated position
|
||||
targetOffset = _calculateEstimatedPosition(index, chipWidth, spacing);
|
||||
}
|
||||
|
||||
scrollController.animateTo(
|
||||
targetOffset.clamp(0.0, scrollController.position.maxScrollExtent),
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
|
||||
double _calculateEstimatedPosition(
|
||||
int index,
|
||||
double chipWidth,
|
||||
double spacing,
|
||||
) {
|
||||
final double itemPosition = (chipWidth + spacing) * index;
|
||||
final double viewportWidth = scrollController.position.viewportDimension;
|
||||
return itemPosition - (viewportWidth / 2) + (chipWidth / 2);
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
scrollController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user