diff --git a/lib/presentation/auth/auth_screen/auth_screen.dart b/lib/presentation/auth/auth_screen/auth_screen.dart index 4cbef203..213e8c29 100644 --- a/lib/presentation/auth/auth_screen/auth_screen.dart +++ b/lib/presentation/auth/auth_screen/auth_screen.dart @@ -87,7 +87,7 @@ class AuthScreen extends StatelessWidget { state.emailController!.text, state.passwordController!.text); if (errors.isEmpty) { - final credentials = { + final Map credentials = { 'email': state.emailController!.text, 'password': state.passwordController!.text, }; 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 81e7f5dc..e1844ed9 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 @@ -1,6 +1,5 @@ import 'dart:async'; -import 'dart:ffi'; - +import 'package:intl/intl.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import '/core/app_export.dart'; @@ -45,6 +44,7 @@ class DiaryEditBloc extends Bloc { final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'), headers: { + 'Content-Type': 'application/json', 'Authorization': 'Bearer $token', }, ); @@ -57,6 +57,7 @@ class DiaryEditBloc extends Bloc { final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/show/$diaryId'), headers: { + 'Content-Type': 'application/json', 'Authorization': 'Bearer $token', }, ); @@ -167,11 +168,12 @@ class DiaryEditBloc extends Bloc { ) async { String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/meal/$mealID/satiety/fill'; - final credentials = { + final Map credentials = { 'satiety': selectedSatiety, }; var response = await http.post(Uri.parse(url), headers: { + 'Content-Type': 'application/json', 'Authorization': 'Bearer $token', }, body: json.encode(credentials), @@ -209,12 +211,13 @@ class DiaryEditBloc extends Bloc { ) async { String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/meal/$mealID/fill'; - final credentials = { + final Map credentials = { 'mood': selectedMood, }; var response = await http.post(Uri.parse(url), headers: { + 'Content-Type': 'application/json', 'Authorization': 'Bearer $token', }, body: json.encode(credentials), @@ -227,7 +230,7 @@ class DiaryEditBloc extends Bloc { WakeupEvent event, Emitter emit) async { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; - var updatedState = + var updatedState = //инициализируем новое состояние currentState.copyWith(wakeupController: event.selectedTime); // Отправляем данные по HTTP маршруту и ждем ответ @@ -235,6 +238,7 @@ class DiaryEditBloc extends Bloc { currentState.token, event.selectedTime, currentState.diaryId); if (response.statusCode == 200) { + //Чекаем статус ответа updatedState.wakeupController = event.selectedTime; emit(updatedState); // Передаем обновленное состояние в emit } @@ -247,17 +251,22 @@ class DiaryEditBloc extends Bloc { int diaryID, ) async { String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/wakeUp/fill'; - final credentials = { - 'wakeup': wakeup, + final formatter = DateFormat('HH:mm'); + final wakeupString = + formatter.format(DateTime(2022, 1, 1, wakeup.hour, wakeup.minute)); + final Map credentials = { + 'wakeup': wakeupString, }; - - var response = await http.post(Uri.parse(url), - headers: { - 'Authorization': 'Bearer $token', - }, - body: json.encode(credentials), - encoding: utf8); - + var response = await http.post( + Uri.parse(url), + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer $token', + }, + body: json.encode(credentials), + encoding: utf8, + ); + print(response.body); return response; } @@ -282,12 +291,13 @@ class DiaryEditBloc extends Bloc { Future sendRetireData( String? token, TimeOfDay retire, int diaryID) async { String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/retire/fill'; - final credentials = { + final Map credentials = { 'retire': retire, }; var response = await http.post(Uri.parse(url), headers: { + 'Content-Type': 'application/json', 'Authorization': 'Bearer $token', }, body: json.encode(credentials), @@ -313,7 +323,7 @@ class DiaryEditBloc extends Bloc { int diaryID, ) async { String url = dotenv.env['SERVER_ROOT']! + '/diary/???'; - final credentials = { + final Map credentials = { 'time': mealTime, 'meal_id': mealID, 'diary_id': diaryID, @@ -321,6 +331,7 @@ class DiaryEditBloc extends Bloc { var response = await http.post(Uri.parse(url), headers: { + 'Content-Type': 'application/json', 'Authorization': 'Bearer $token', }, body: json.encode(credentials), @@ -403,7 +414,7 @@ class DiaryEditBloc extends Bloc { ) async { String url = dotenv.env['SERVER_ROOT']! + 'diary/$diaryID/meal/$mealID/portions/create'; - final credentials = { + final Map credentials = { 'product_name': name, 'portion': portion, 'quantity': quantity, @@ -411,6 +422,7 @@ class DiaryEditBloc extends Bloc { var response = await http.post(Uri.parse(url), headers: { + 'Content-Type': 'application/json', 'Authorization': 'Bearer $token', }, body: json.encode(credentials), @@ -424,7 +436,7 @@ class DiaryEditBloc extends Bloc { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; String? token = currentState.token; - final credentials = { + final Map credentials = { 'name': event.input, }; final uri = Uri.parse(dotenv.env['SERVER_ROOT']! + @@ -433,6 +445,7 @@ class DiaryEditBloc extends Bloc { final response = await http.get( uri, headers: { + 'Content-Type': 'application/json', 'Authorization': 'Bearer $token', }, ); @@ -481,12 +494,13 @@ class DiaryEditBloc extends Bloc { Future sendCommentData( String? token, String comment, int diaryID) async { String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/retire/fill'; - final credentials = { + final Map credentials = { 'comment': comment, }; var response = await http.post(Uri.parse(url), headers: { + 'Content-Type': 'application/json', 'Authorization': 'Bearer $token', }, body: json.encode(credentials),