feat(app): Initial layouts for subscribers, feed display fix, feed photo upload front end

This commit is contained in:
2024-06-27 13:17:53 +03:00
parent 6e7f1acf46
commit b1508c3553
12 changed files with 709 additions and 184 deletions

View File

@@ -48,10 +48,10 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
data.containsKey('userDetails') &&
data.containsKey('chartPoints') &&
data.containsKey('circumferences')) {
final avatarBox = await Hive.openBox('avatar');
final avatar = data['user']['profile_photo_path'];
print(avatar);
avatarBox.put('avatar', avatar);
final avatarBox = await Hive.openBox('avatar');
final avatar = data['user']['profile_photo_path'];
print(avatar);
avatarBox.put('avatar', avatar);
if (state is MyProfileLoadedState) {
var currentState = state as MyProfileLoadedState;
var plans = []
@@ -61,46 +61,48 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
..addAll(data["paidPlan"])
..addAll(data["requestedPlan"])
..addAll(data["initedPlan"]);
emit((currentState).copyWith(
chartPoints: currentState.chartPoints,
chartDates: currentState.chartDates,
circumferences: currentState.circumferences,
user: data['user'],
userDetails: data['userDetails'],
plans: plans,
token: token,
chestCircumferenceController: TextEditingController(),
waistCircumferenceController: TextEditingController(),
hipCircumferenceController: TextEditingController(),
weightController: TextEditingController(),
chestCircumferenceFormController:
currentState.chestCircumferenceFormController,
waistCircumferenceFormController:
currentState.waistCircumferenceFormController,
hipCircumferenceFormController:
currentState.hipCircumferenceFormController,
firstNameFormController: currentState.firstNameFormController,
lastNameFormController: currentState.lastNameFormController,
countryFormController: currentState.countryFormController,
cityFormController: currentState.cityFormController,
heightFormController: currentState.heightFormController,
upPressureFormController: currentState.upPressureFormController,
downPressureFormController:
currentState.downPressureFormController,
allergiesFormController: currentState.allergiesFormController,
pillsFormController: currentState.pillsFormController,
favoriteFormController: currentState.favoriteFormController,
unfavoriteFormController: currentState.unfavoriteFormController,
additionalFormController: currentState.additionalFormController,
sportsFormController: currentState.sportsFormController,
dateFormController: currentState.dateFormController,
hypoFormController: currentState.hypoFormController,
hyperFormController: currentState.hyperFormController,
selectedCity: currentState.selectedCity,
selectedCountry: currentState.selectedCountry,
selectedActivity: currentState.selectedActivity,
myProfileModelObj: currentState.myProfileModelObj,
),);
emit(
(currentState).copyWith(
chartPoints: currentState.chartPoints,
chartDates: currentState.chartDates,
circumferences: currentState.circumferences,
user: data['user'],
userDetails: data['userDetails'],
plans: plans,
token: token,
chestCircumferenceController: TextEditingController(),
waistCircumferenceController: TextEditingController(),
hipCircumferenceController: TextEditingController(),
weightController: TextEditingController(),
chestCircumferenceFormController:
currentState.chestCircumferenceFormController,
waistCircumferenceFormController:
currentState.waistCircumferenceFormController,
hipCircumferenceFormController:
currentState.hipCircumferenceFormController,
firstNameFormController: currentState.firstNameFormController,
lastNameFormController: currentState.lastNameFormController,
countryFormController: currentState.countryFormController,
cityFormController: currentState.cityFormController,
heightFormController: currentState.heightFormController,
upPressureFormController: currentState.upPressureFormController,
downPressureFormController:
currentState.downPressureFormController,
allergiesFormController: currentState.allergiesFormController,
pillsFormController: currentState.pillsFormController,
favoriteFormController: currentState.favoriteFormController,
unfavoriteFormController: currentState.unfavoriteFormController,
additionalFormController: currentState.additionalFormController,
sportsFormController: currentState.sportsFormController,
dateFormController: currentState.dateFormController,
hypoFormController: currentState.hypoFormController,
hyperFormController: currentState.hyperFormController,
selectedCity: currentState.selectedCity,
selectedCountry: currentState.selectedCountry,
selectedActivity: currentState.selectedActivity,
myProfileModelObj: currentState.myProfileModelObj,
),
);
} else {
var plans = []
..addAll(data["finishedPlans"])
@@ -166,67 +168,87 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
}
}
emit(MyProfileLoadedState(
chartPoints: chartPoints,
chartDates: dates,
circumferences: circumferences,
user: data['user'],
userDetails: data['userDetails'],
plans: plans,
token: token,
chestCircumferenceController: TextEditingController(),
waistCircumferenceController: TextEditingController(),
hipCircumferenceController: TextEditingController(),
hypoFormController: data['userDetails']['has_hypo'].toString(),
hyperFormController: data['userDetails']['has_hyper'].toString(),
chestCircumferenceFormController: TextEditingController(
text: data['userDetails']['chest_circumference']?.toString(),),
waistCircumferenceFormController: TextEditingController(
text: data['userDetails']['waist_circumference']?.toString(),),
hipCircumferenceFormController: TextEditingController(
text: data['userDetails']['hip_circumference']?.toString(),),
weightController: TextEditingController(
text: data['userDetails']['weight']?.toString(),),
weightFormController: TextEditingController(
text: data['userDetails']['weight']?.toString(),),
firstNameFormController: TextEditingController(
text: data['userDetails']['first_name'],),
lastNameFormController:
TextEditingController(text: data['userDetails']['last_name']),
countryFormController:
TextEditingController(text: data['userDetails']['country']),
cityFormController:
TextEditingController(text: data['userDetails']['city']),
heightFormController: TextEditingController(
text: data['userDetails']['height']?.toString(),),
upPressureFormController: TextEditingController(
text: data['userDetails']['blood_pressure_up']?.toString(),),
downPressureFormController: TextEditingController(
text: data['userDetails']['blood_pressure_down']?.toString(),),
allergiesFormController: TextEditingController(
text: data['userDetails']['about_alergy'],),
pillsFormController: TextEditingController(
text: data['userDetails']['about_taking_pils'],),
sportsFormController: TextEditingController(
text: data['userDetails']['about_sport_hobbies'],),
favoriteFormController: TextEditingController(
text: data['userDetails']['favorite_foods'],),
unfavoriteFormController: TextEditingController(
text: data['userDetails']['unfavorite_foods'],),
additionalFormController: TextEditingController(
text: data['userDetails']['additional_info'],),
dateFormController:
TextEditingController(text: data['userDetails']['birthdate']),
selectedCity: data['userDetails']['city'],
selectedCountry: data['userDetails']['country'],
selectedActivity: determineActivityLevel(
data['userDetails']['activity_coefficient'],),
),);
emit(
MyProfileLoadedState(
chartPoints: chartPoints,
chartDates: dates,
circumferences: circumferences,
user: data['user'],
userDetails: data['userDetails'],
plans: plans,
token: token,
chestCircumferenceController: TextEditingController(),
waistCircumferenceController: TextEditingController(),
hipCircumferenceController: TextEditingController(),
hypoFormController: data['userDetails']['has_hypo'].toString(),
hyperFormController:
data['userDetails']['has_hyper'].toString(),
chestCircumferenceFormController: TextEditingController(
text: data['userDetails']['chest_circumference']?.toString(),
),
waistCircumferenceFormController: TextEditingController(
text: data['userDetails']['waist_circumference']?.toString(),
),
hipCircumferenceFormController: TextEditingController(
text: data['userDetails']['hip_circumference']?.toString(),
),
weightController: TextEditingController(
text: data['userDetails']['weight']?.toString(),
),
weightFormController: TextEditingController(
text: data['userDetails']['weight']?.toString(),
),
firstNameFormController: TextEditingController(
text: data['userDetails']['first_name'],
),
lastNameFormController: TextEditingController(
text: data['userDetails']['last_name']),
countryFormController:
TextEditingController(text: data['userDetails']['country']),
cityFormController:
TextEditingController(text: data['userDetails']['city']),
heightFormController: TextEditingController(
text: data['userDetails']['height']?.toString(),
),
upPressureFormController: TextEditingController(
text: data['userDetails']['blood_pressure_up']?.toString(),
),
downPressureFormController: TextEditingController(
text: data['userDetails']['blood_pressure_down']?.toString(),
),
allergiesFormController: TextEditingController(
text: data['userDetails']['about_alergy'],
),
pillsFormController: TextEditingController(
text: data['userDetails']['about_taking_pils'],
),
sportsFormController: TextEditingController(
text: data['userDetails']['about_sport_hobbies'],
),
favoriteFormController: TextEditingController(
text: data['userDetails']['favorite_foods'],
),
unfavoriteFormController: TextEditingController(
text: data['userDetails']['unfavorite_foods'],
),
additionalFormController: TextEditingController(
text: data['userDetails']['additional_info'],
),
dateFormController: TextEditingController(
text: data['userDetails']['birthdate']),
selectedCity: data['userDetails']['city'],
selectedCountry: data['userDetails']['country'],
selectedActivity: determineActivityLevel(
data['userDetails']['activity_coefficient'],
),
),
);
}
} else {
// Один или несколько ключевых полей отсутствуют, обрабатываем ошибку
emit(
MyProfileErrorState('Некоторые необходимые данные отсутствуют.'),);
MyProfileErrorState('Некоторые необходимые данные отсутствуют.'),
);
}
} else {
// Статус ответа не равен 200, обрабатываем ошибку
@@ -253,7 +275,9 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
} // колхоз, но свитчкейсы в дарте странно ведут себя при сравнении double
Future<void> _uploadAvatar(
UploadAvatar event, Emitter<MyProfileState> emit,) async {
UploadAvatar event,
Emitter<MyProfileState> emit,
) async {
if (state is MyProfileLoadedState) {
var currentState = state as MyProfileLoadedState;
@@ -279,7 +303,8 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
return imageUrl;
} else {
throw Exception(
'Failed to upload image. Status code: ${streamedResponse.statusCode} ${streamedResponse}}',);
'Failed to upload image. Status code: ${streamedResponse.statusCode} ${streamedResponse}}',
);
}
}
}