forked from eatvio/eatvio_app
feat(diary): Preloader added when uploading images
This commit is contained in:
@@ -298,6 +298,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
carbsController: TextEditingController(),
|
||||
diaryId: diaryId,
|
||||
diaryDate: diaryDate,
|
||||
isLoading: false,
|
||||
autocompleteList: [],
|
||||
)));
|
||||
|
||||
@@ -800,6 +801,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
|
||||
emit(currentState.copyWith(isLoading: true));
|
||||
await uploadImageToServer(event.image.path, currentState.diaryId,
|
||||
currentState.currentMeal!.id!, currentState.token);
|
||||
await reloadScreen(event, emit);
|
||||
|
||||
@@ -39,6 +39,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
this.fatsController,
|
||||
this.proteinsController,
|
||||
this.carbsController,
|
||||
this.isLoading = false,
|
||||
required this.recommendedChartValues,
|
||||
required this.consumedChartValues,
|
||||
required this.diaryId,
|
||||
@@ -75,6 +76,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
bool wakeupExpanded;
|
||||
bool moderationExpanded;
|
||||
bool moodExpanded;
|
||||
bool isLoading;
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
diaryEditModelObj,
|
||||
@@ -103,6 +105,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
wakeupExpanded,
|
||||
moodExpanded,
|
||||
moderationExpanded,
|
||||
isLoading,
|
||||
currentMeal
|
||||
];
|
||||
DiaryEditLoadedState copyWith({
|
||||
@@ -133,6 +136,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
bool? wakeupExpanded,
|
||||
bool? moderationExpanded,
|
||||
bool? moodExpanded,
|
||||
bool? isLoading,
|
||||
}) {
|
||||
return DiaryEditLoadedState(
|
||||
diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj,
|
||||
@@ -164,7 +168,8 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
carbsController: carbsController ?? this.carbsController,
|
||||
wakeupExpanded: wakeupExpanded ?? this.wakeupExpanded,
|
||||
moderationExpanded: moderationExpanded ?? this.moderationExpanded,
|
||||
moodExpanded: moodExpanded ?? this.moodExpanded);
|
||||
moodExpanded: moodExpanded ?? this.moodExpanded,
|
||||
isLoading: isLoading ?? this.isLoading);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -176,53 +176,79 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// Section Widget
|
||||
_buildAddPhoto(BuildContext context) {
|
||||
_buildAddPhoto(BuildContext context, DiaryEditLoadedState state) {
|
||||
bool isLoading = state.isLoading;
|
||||
return GestureDetector(
|
||||
onTap: addImage(context),
|
||||
child: Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 40.h,
|
||||
vertical: 80.v,
|
||||
),
|
||||
decoration: AppDecoration.fillGray.copyWith(
|
||||
borderRadius: BorderRadiusStyle.roundedBorder5,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 7.h,
|
||||
top: 5.v,
|
||||
onTap: addImage(context, isLoading),
|
||||
child: Stack(
|
||||
children: [
|
||||
if (!isLoading)
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 40.h,
|
||||
vertical: 80.v,
|
||||
),
|
||||
child: Text(
|
||||
"Добавить фото",
|
||||
selectionColor: appTheme.blueA400,
|
||||
decoration: AppDecoration.fillGray.copyWith(
|
||||
borderRadius: BorderRadiusStyle.roundedBorder5,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Показывайте прелоадер, если загрузка активна
|
||||
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 7.h,
|
||||
top: 5.v,
|
||||
),
|
||||
child: Text(
|
||||
"Добавить фото",
|
||||
selectionColor: appTheme.blueA400,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Icon(
|
||||
Icons.photo_library,
|
||||
color: appTheme.blueGray300,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Icon(
|
||||
Icons.photo_library,
|
||||
color: appTheme.blueGray300,
|
||||
)
|
||||
],
|
||||
),
|
||||
if (isLoading)
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 40.h,
|
||||
vertical: 80.v,
|
||||
),
|
||||
decoration: AppDecoration.fillGray.copyWith(
|
||||
borderRadius: BorderRadiusStyle.roundedBorder5,
|
||||
),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: appTheme
|
||||
.blueGray300), // Замените на свой прелоадер при необходимости
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
addImage(BuildContext context) {
|
||||
return () async {
|
||||
final picker = ImagePicker();
|
||||
List<XFile>? images = await picker.pickMultiImage();
|
||||
if (images.isNotEmpty) {
|
||||
for (var image in images) {
|
||||
context.read<DiaryEditBloc>().add(UploadImages(image));
|
||||
addImage(BuildContext context, bool isLoading) {
|
||||
if (!isLoading) {
|
||||
return () async {
|
||||
final picker = ImagePicker();
|
||||
List<XFile>? images = await picker.pickMultiImage();
|
||||
if (images.isNotEmpty) {
|
||||
for (var image in images) {
|
||||
context.read<DiaryEditBloc>().add(UploadImages(image));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
_buildMeal(BuildContext context, DiaryEditLoadedState state) {
|
||||
@@ -411,7 +437,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
: [Text('Фото нет')],*/
|
||||
_buildCarousel(context, state),
|
||||
SizedBox(height: 20.v),
|
||||
_buildAddPhoto(context),
|
||||
_buildAddPhoto(context, state),
|
||||
SizedBox(height: 30.v),
|
||||
Text(
|
||||
"Ваша сытость после приёма пищи",
|
||||
|
||||
Reference in New Issue
Block a user