forked from eatvio/eatvio_app
<feat>[profile]: Finished user profile edit
This commit is contained in:
@@ -114,7 +114,6 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
|
||||
"0000-00-00 00:00:00"
|
||||
];
|
||||
for (int i = 0; i < data["chartPoints"].length; i++) {
|
||||
print(data["chartPoints"][i]["weight"]);
|
||||
weights[i] = data["chartPoints"][i]["weight"].toDouble();
|
||||
dates[i] = data["chartPoints"][i]["created_at"].toString();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:eatvio_app/widgets/next_step_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class MySettingsScreen extends StatelessWidget {
|
||||
@@ -569,21 +570,41 @@ class _ExpandableListState extends State<ExpandableList> {
|
||||
'has_hypo': state?.hypoFormController,
|
||||
'has_hyper': state?.hyperFormController,
|
||||
};
|
||||
|
||||
print(profileData);
|
||||
// Отправляем JSON на сервер
|
||||
String apiUrl = dotenv.env['SERVER_ROOT']! + 'profile/edit';
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
String apiUrl = dotenv.env['SERVER_ROOT']! + '/profile/edit';
|
||||
http.Response response = await http.post(
|
||||
Uri.parse(apiUrl),
|
||||
body: json.encode(profileData),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
encoding: utf8,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
);
|
||||
|
||||
// Проверяем ответ от сервера
|
||||
print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
// Редирект
|
||||
// ваш код для редиректа
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.myProfile,
|
||||
);
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Ошибка'),
|
||||
content: Text('Ошибка при отправке данных профиля'.tr),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
throw Exception('Ошибка при отправке данных профиля');
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user