From 51226653704eb0dedbca91c0c581765e015decdf Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 11 Apr 2024 16:24:10 +0300 Subject: [PATCH] refactor(app): Assemble release --- .../bloc/diary_edit_bloc.dart | 15 ++++++++----- .../diary_edit_screen/diary_edit_screen.dart | 20 +++++++++++++++-- .../additional_information_screen.dart | 22 +++++++++++-------- lib/widgets/custom_bottom_bar.dart | 2 +- lib/widgets/custom_expandable_list.dart | 6 +++-- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart index 67bfa95b..5a04a681 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart @@ -7,6 +7,7 @@ import 'package:image_picker/image_picker.dart'; import 'package:eatvio_app/presentation/diary/diary_edit_screen/models/diary_edit_model.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; +import 'package:hive/hive.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; part 'diary_edit_event.dart'; @@ -44,9 +45,10 @@ class DiaryEditBloc extends Bloc { Emitter emit, ) async { try { - final token = - "9|laravel_sanctum_KFXbccDcWEvTPfJmV99EQv1neAggmpR2TidVGDPN34fa201a"; - + // final token = + // "9|laravel_sanctum_KFXbccDcWEvTPfJmV99EQv1neAggmpR2TidVGDPN34fa201a"; + final box = await Hive.openBox('token'); + final token = box.get('token'); //print(await fetchDiaryId(token)); final int diaryId = await fetchDiaryId(token); try { @@ -215,9 +217,10 @@ class DiaryEditBloc extends Bloc { ) async { print("Reloading..."); try { - final token = - "9|laravel_sanctum_KFXbccDcWEvTPfJmV99EQv1neAggmpR2TidVGDPN34fa201a"; - + //final token = + // "9|laravel_sanctum_KFXbccDcWEvTPfJmV99EQv1neAggmpR2TidVGDPN34fa201a"; final box = await Hive.openBox('token'); + final box = await Hive.openBox('token'); + final token = box.get('token'); final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'), headers: { diff --git a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart index 0fcfe9e6..d03631be 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -14,6 +14,7 @@ import 'package:eatvio_app/widgets/custom_edit_drop_down.dart'; import 'package:eatvio_app/widgets/custom_outlined_button.dart'; import 'package:eatvio_app/widgets/custom_scale_element.dart'; import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; +import 'package:carousel_slider/carousel_slider.dart'; // ignore: must_be_immutable class DiaryEditScreen extends StatelessWidget { @@ -401,13 +402,14 @@ class DiaryEditScreen extends StatelessWidget { .map((portion) => _buildProduct(context, portion)) .toList(), SizedBox(height: 30.v), - ...state.photos != null + /*...state.photos != null ? state.photos!.isEmpty ? [Text('Фото пока нет')] : state.photos! .map((photo) => _buildPhoto(context, photo)) .toList() - : [Text('Фото нет')], + : [Text('Фото нет')],*/ + _buildCarousel(context, state), SizedBox(height: 20.v), _buildAddPhoto(context), SizedBox(height: 30.v), @@ -601,6 +603,20 @@ class DiaryEditScreen extends StatelessWidget { }; } + _buildCarousel(BuildContext context, DiaryEditLoadedState state) { + if (state.photos!.isEmpty) { + return Text("Фото нет"); + } else { + return CarouselSlider( + options: CarouselOptions(height: 340.0), + items: state.photos!.map((photo) { + return _buildPhoto( + context, photo); // Assuming photos are stored as strings + }).toList(), + ); + } + } + _buildProduct(BuildContext context, Map portion) { return Container( margin: EdgeInsets.symmetric(horizontal: 10.h), diff --git a/lib/presentation/registration/additional_information_screen/additional_information_screen.dart b/lib/presentation/registration/additional_information_screen/additional_information_screen.dart index 7f632e21..0ea7e7dd 100644 --- a/lib/presentation/registration/additional_information_screen/additional_information_screen.dart +++ b/lib/presentation/registration/additional_information_screen/additional_information_screen.dart @@ -76,16 +76,18 @@ class AdditionalInformationScreen extends StatelessWidget { UserRegistrationSheet sheet = state.additionalInformationModelObj!.userRegistrationSheet; sheet.additionalInfo = state.editTextController!.text; - //print(json.encode(sheet.toJson())); + final response = await http.post( Uri.parse(dotenv.env['SERVER_ROOT']! + '/register'), - headers: {'Content-Type': 'application/json'}, - body: jsonEncode(sheet), + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }, + body: jsonEncode(sheet.toJson()), encoding: utf8); - print(jsonEncode(sheet.toJson())); - print(Uri.parse(dotenv.env['SERVER_ROOT']! + '/register')); + + var res = await jsonDecode(response.body); if (response.statusCode == 200) { - var res = await jsonDecode(response.body); final box = await Hive.openBox('token'); final token = res['token']; box.put('token', token); @@ -93,6 +95,8 @@ class AdditionalInformationScreen extends StatelessWidget { context, AppRoutes.myProfile, ); + } else { + showErrorMessage(context, res['message']); } }; } @@ -152,12 +156,12 @@ class AdditionalInformationScreen extends StatelessWidget { /// Displays an alert dialog when the action is triggered. /// The dialog box contains a title and a message with the `Теперь вы можете пользоваться полным функционалом приложения` - showSuccessMessage(BuildContext context, String text) { + showErrorMessage(BuildContext context, String text) { showDialog( context: context, builder: (_) => AlertDialog( - title: const Text('Регистрация завершена!'), - content: const Text('1'), + title: const Text('Ошибка'), + content: Text(text), actions: [ TextButton(onPressed: onTapOk(context), child: const Text('Ok')) ], diff --git a/lib/widgets/custom_bottom_bar.dart b/lib/widgets/custom_bottom_bar.dart index 71ee1bfb..cf1ecba6 100644 --- a/lib/widgets/custom_bottom_bar.dart +++ b/lib/widgets/custom_bottom_bar.dart @@ -34,7 +34,7 @@ class CustomBottomBarState extends State { type: BottomBarEnum.tf, ), BottomMenuModel( - icon: ImageConstant.imgNavBlueGray40024x23, + icon: ImageConstant.imgNavPrimary, activeIcon: ImageConstant.imgNavBlueGray40024x23, title: "Настройки", type: BottomBarEnum.tf, diff --git a/lib/widgets/custom_expandable_list.dart b/lib/widgets/custom_expandable_list.dart index 007a8156..b8b8edf0 100644 --- a/lib/widgets/custom_expandable_list.dart +++ b/lib/widgets/custom_expandable_list.dart @@ -340,7 +340,7 @@ class _ExpandableListState extends State { 'weight': state?.weightFormController?.text, 'blood_pressure_up': state?.upPressureFormController?.text, 'blood_pressure_down': state?.downPressureFormController?.text, - 'about_alergy': state?.allergiesFormController?.text, + 'about_alergy': state?.allergiesFormController?.text ?? 'Нет аллергий', 'about_taking_pils': state?.pillsFormController?.text, 'about_sport_hobbies': state?.sportsFormController?.text, 'favorite_foods': state?.favoriteFormController?.text, @@ -362,6 +362,7 @@ class _ExpandableListState extends State { encoding: utf8, headers: { 'Content-Type': 'application/json', + 'Accept': 'application/json', 'Authorization': 'Bearer $token', }, ); @@ -373,11 +374,12 @@ class _ExpandableListState extends State { AppRoutes.myProfile, ); } else { + var res = await jsonDecode(response.body); showDialog( context: context, builder: (context) => AlertDialog( title: Text('Ошибка'), - content: Text('Ошибка при отправке данных профиля'.tr), + content: Text(res['message']), actions: [ TextButton( onPressed: onTapOk(context),