forked from eatvio/eatvio_app
feat(diary): Encoding error fix for satiety
This commit is contained in:
@@ -87,7 +87,7 @@ class AuthScreen extends StatelessWidget {
|
||||
state.emailController!.text,
|
||||
state.passwordController!.text);
|
||||
if (errors.isEmpty) {
|
||||
final credentials = {
|
||||
final Map<String, dynamic> credentials = {
|
||||
'email': state.emailController!.text,
|
||||
'password': state.passwordController!.text,
|
||||
};
|
||||
|
||||
@@ -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<DiaryEditEvent, DiaryEditState> {
|
||||
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<DiaryEditEvent, DiaryEditState> {
|
||||
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<DiaryEditEvent, DiaryEditState> {
|
||||
) async {
|
||||
String url = dotenv.env['SERVER_ROOT']! +
|
||||
'/diary/$diaryID/meal/$mealID/satiety/fill';
|
||||
final credentials = {
|
||||
final Map<String, dynamic> 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<DiaryEditEvent, DiaryEditState> {
|
||||
) async {
|
||||
String url =
|
||||
dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/meal/$mealID/fill';
|
||||
final credentials = {
|
||||
final Map<String, dynamic> 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<DiaryEditEvent, DiaryEditState> {
|
||||
WakeupEvent event, Emitter<DiaryEditState> 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<DiaryEditEvent, DiaryEditState> {
|
||||
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<DiaryEditEvent, DiaryEditState> {
|
||||
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<String, dynamic> 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<DiaryEditEvent, DiaryEditState> {
|
||||
Future<http.Response> sendRetireData(
|
||||
String? token, TimeOfDay retire, int diaryID) async {
|
||||
String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/retire/fill';
|
||||
final credentials = {
|
||||
final Map<String, dynamic> 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<DiaryEditEvent, DiaryEditState> {
|
||||
int diaryID,
|
||||
) async {
|
||||
String url = dotenv.env['SERVER_ROOT']! + '/diary/???';
|
||||
final credentials = {
|
||||
final Map<String, dynamic> credentials = {
|
||||
'time': mealTime,
|
||||
'meal_id': mealID,
|
||||
'diary_id': diaryID,
|
||||
@@ -321,6 +331,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
|
||||
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<DiaryEditEvent, DiaryEditState> {
|
||||
) async {
|
||||
String url = dotenv.env['SERVER_ROOT']! +
|
||||
'diary/$diaryID/meal/$mealID/portions/create';
|
||||
final credentials = {
|
||||
final Map<String, dynamic> credentials = {
|
||||
'product_name': name,
|
||||
'portion': portion,
|
||||
'quantity': quantity,
|
||||
@@ -411,6 +422,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
|
||||
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<DiaryEditEvent, DiaryEditState> {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
String? token = currentState.token;
|
||||
final credentials = {
|
||||
final Map<String, dynamic> credentials = {
|
||||
'name': event.input,
|
||||
};
|
||||
final uri = Uri.parse(dotenv.env['SERVER_ROOT']! +
|
||||
@@ -433,6 +445,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
final response = await http.get(
|
||||
uri,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
);
|
||||
@@ -481,12 +494,13 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
Future<http.Response> sendCommentData(
|
||||
String? token, String comment, int diaryID) async {
|
||||
String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/retire/fill';
|
||||
final credentials = {
|
||||
final Map<String, dynamic> credentials = {
|
||||
'comment': comment,
|
||||
};
|
||||
|
||||
var response = await http.post(Uri.parse(url),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
body: json.encode(credentials),
|
||||
|
||||
Reference in New Issue
Block a user