forked from eatvio/eatvio_app
feat(diary): Trying to fix redirect after API call
This commit is contained in:
@@ -18,8 +18,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
on<DiaryEditInitialEvent>(_onInitialize);
|
||||
on<ChangeSatiety>(_changeSatiety); // пользователь нажимает на шкалу сытости
|
||||
on<ChangeMood>(_changeMood); // пользователь нажимает на шкалу настроения
|
||||
on<ChangeMealTime>(
|
||||
_changeMealTime); // пользователь изменяет время приема пиши
|
||||
on<ChangeMealTime>(_changeMealTime); // пользовательяет времяа пиши
|
||||
on<ChangeMeal>(_changeMeal);
|
||||
on<WakeupEvent>(_changeWakeup); // пользователь выбирает время пробуждения
|
||||
on<RetireEvent>(_changeRetire); // пользователь выбирает время отхода ко сну
|
||||
@@ -44,7 +43,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
) async {
|
||||
try {
|
||||
final token =
|
||||
"laravel_sanctum_1lPFtd9tpGmHYS243C4K7YF8BrVhxxgXm8cTmjuZda1da694";
|
||||
"9|laravel_sanctum_KFXbccDcWEvTPfJmV99EQv1neAggmpR2TidVGDPN34fa201a";
|
||||
final response = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'),
|
||||
headers: {
|
||||
@@ -52,14 +51,13 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
if (data is Map<String, dynamic> && data.containsKey('id')) {
|
||||
final int diaryId = data['id'];
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/show/$diaryId'),
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/$diaryId/show/'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
@@ -143,7 +141,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
}
|
||||
} catch (e) {
|
||||
// Ошибка при получении данных дневника
|
||||
emit(DiaryEditErrorState('Ошибка при получении данных дневника: $e'));
|
||||
emit(DiaryEditErrorState('Ошибка при получении данных о дневнике: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +149,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
print("Reloading...");
|
||||
try {
|
||||
final token =
|
||||
"laravel_sanctum_1lPFtd9tpGmHYS243C4K7YF8BrVhxxgXm8cTmjuZda1da694";
|
||||
"9|laravel_sanctum_KFXbccDcWEvTPfJmV99EQv1neAggmpR2TidVGDPN34fa201a";
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'),
|
||||
@@ -167,7 +165,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
final int diaryId = data['id'];
|
||||
|
||||
final diaryResponse = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/show/$diaryId'),
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/$diaryId/show/'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
@@ -176,7 +174,6 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
|
||||
final diary = jsonDecode(diaryResponse.body)['diary'];
|
||||
|
||||
print(diary);
|
||||
if (diary is Map<String, dynamic>) {
|
||||
final String diaryDate = diary['date'] ?? DateTime.now().toString();
|
||||
// Продолжайте обработку данных дневника
|
||||
@@ -545,7 +542,6 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
.map((product) => product['name'])
|
||||
.toList(),
|
||||
);
|
||||
print(event.input.length);
|
||||
if (event.input.length > 3) {
|
||||
updatedState = updatedState.copyWith(moderationExpanded: true);
|
||||
} else {
|
||||
@@ -642,7 +638,6 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
encoding: utf8,
|
||||
);
|
||||
|
||||
print(response.body);
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -665,11 +660,11 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
String imagePath, int diaryID, int mealId, String? token) async {
|
||||
String url =
|
||||
'${dotenv.env['SERVER_ROOT']!}/diary/$diaryID/meal/$mealId/photo/upload';
|
||||
// 'https://eo6yh2uv84lm3p0.m.pipedream.net'; // Remove this line and uncomment the above line for actual server URL
|
||||
|
||||
var request = http.MultipartRequest('POST', Uri.parse(url));
|
||||
request.headers.addAll({
|
||||
'Authorization': 'Bearer $token',
|
||||
});
|
||||
request.headers['Authorization'] = 'Bearer $token';
|
||||
request.headers['Content-Type'] = 'multipart/form-data';
|
||||
|
||||
request.files.add(await http.MultipartFile.fromPath('image', imagePath));
|
||||
|
||||
@@ -679,7 +674,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
return imageUrl;
|
||||
} else {
|
||||
throw Exception(
|
||||
'Failed to upload image. Status code: ${response.statusCode}');
|
||||
'Failed to upload image. Status code: ${response.statusCode}}');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,7 +682,6 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
SendModeration event, Emitter<DiaryEditState> emit) async {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
print("sad");
|
||||
final response = await _sendModerationData(
|
||||
event.name,
|
||||
event.energyOn100gr,
|
||||
@@ -710,6 +704,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
String? token) async {
|
||||
String url =
|
||||
'${dotenv.env['SERVER_ROOT']!}/diary/product_nutritional_values/sendToModeration';
|
||||
var serverURL = Uri.parse('${dotenv.env['SERVER_ROOT']!}');
|
||||
String host = serverURL.host;
|
||||
final Map<String, dynamic> credentials = {
|
||||
'name': name,
|
||||
'energy_on_100gr': energy_on_100gr,
|
||||
@@ -717,14 +713,16 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
'fats_on_100gr': fats_on_100gr,
|
||||
'carbohydrates_on_100gr': carbohydrates_on_100gr,
|
||||
};
|
||||
var bodyBytes = utf8.encode(json.encode(credentials));
|
||||
var response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': '${bodyBytes.length}',
|
||||
'Authorization': 'Bearer $token',
|
||||
'Host': host,
|
||||
},
|
||||
body: json.encode(credentials),
|
||||
encoding: utf8,
|
||||
body: bodyBytes,
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
return response;
|
||||
|
||||
@@ -33,9 +33,8 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
builder: (context, state) {
|
||||
if (state is DiaryEditInitialState) {
|
||||
// Это начальное состояние, данные ещё не загружены.
|
||||
return CircularProgressIndicator(
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
backgroundColor: Colors.white,
|
||||
);
|
||||
} else if (state is DiaryEditLoadedState) {
|
||||
// Данные загружены, можно строить экран.
|
||||
@@ -757,37 +756,6 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8.v),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 4.h),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"Калории",
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 28.h),
|
||||
child: Text(
|
||||
"Белки",
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Text(
|
||||
"Жиры",
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 25.h),
|
||||
child: Text(
|
||||
"Углеводы",
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 2.v),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
@@ -893,23 +861,6 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget newMethod(double value) {
|
||||
switch (value.toInt()) {
|
||||
case 0:
|
||||
return Text('Calories');
|
||||
case 1:
|
||||
return Text('Fat');
|
||||
case 2:
|
||||
return Text('Protein');
|
||||
case 3:
|
||||
return Text('Carbs');
|
||||
default:
|
||||
return Text('');
|
||||
}
|
||||
}
|
||||
|
||||
buildBars(BuildContext context, DiaryEditLoadedState state) {}
|
||||
|
||||
/// Section Widget
|
||||
_buildComment(BuildContext context, DiaryEditLoadedState state) {
|
||||
return Container(
|
||||
|
||||
Reference in New Issue
Block a user