refactor(diary): Compiled version apk: profile, settings, diarym registration, auth, navigation bar

This commit is contained in:
2024-04-10 17:07:56 +03:00
parent f4ddb7285c
commit bbbc20a15a
11 changed files with 164 additions and 133 deletions

View File

@@ -4,7 +4,7 @@ import '/core/app_export.dart';
import 'package:eatvio_app/presentation/profile/my_profile_screen/models/my_profile_model.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
//import 'package:hive/hive.dart';
import 'package:hive/hive.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
part 'my_profile_event.dart';
@@ -21,28 +21,24 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
Emitter<MyProfileState> emit,
) async {
try {
/*final box = await Hive.openBox('token');
final token = box.get('token');*/
final token =
"9|laravel_sanctum_KFXbccDcWEvTPfJmV99EQv1neAggmpR2TidVGDPN34fa201a";
final box = await Hive.openBox('token');
final token = box.get('token');
//final token =
// "9|laravel_sanctum_KFXbccDcWEvTPfJmV99EQv1neAggmpR2TidVGDPN34fa201a";
final response = await http.get(
Uri.parse(dotenv.env['SERVER_ROOT']! + '/profile/index'),
headers: {
'Authorization': 'Bearer $token',
},
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
// Проверка наличия ключевых полей в JSON
if (data is Map<String, dynamic> &&
data.containsKey('user') &&
data.containsKey('userDetails') &&
data.containsKey('chartPoints') &&
data.containsKey('circumferences')) {
// Все ключевые поля присутствуют, продолжаем обработку
if (state is MyProfileLoadedState) {
// Если текущее состояние уже загружено, обновляем его
var currentState = state as MyProfileLoadedState;
var plans = []
..addAll(data["finishedPlans"])
@@ -51,9 +47,6 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
..addAll(data["paidPlan"])
..addAll(data["requestedPlan"])
..addAll(data["initedPlan"]);
// Обновляем значения контроллеров только если они уже были созданы
emit((currentState).copyWith(
chartPoints: currentState.chartPoints,
chartDates: currentState.chartDates,
@@ -123,18 +116,6 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
})
: data["chartPoints"];
/*List<double> weights = [0.0, 0.0, 0.0, 0.0];
List<String> dates = [
"0000-00-00 00:00:00",
"0000-00-00 00:00:00",
"0000-00-00 00:00:00",
"0000-00-00 00:00:00"
];
for (int i = 0; i < data["chartPoints"].length; i++) {
weights[i] = data["chartPoints"][i]["weight"].toDouble();
dates[i] = data["chartPoints"][i]["created_at"].toString();
}
print(data);*/
List<String> dates = [
"0000-00-00 00:00:00",
"0000-00-00 00:00:00",
@@ -169,14 +150,7 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
};
}
}
print(data['userDetails']);
/*print(chartPoints);
print(circumferences);*/
/*print(weights);
print(weights.runtimeType);
print(circumferences);
print(circumferences.runtimeType);*/
// Если текущее состояние - начальное, создаем новое загруженное состояние
emit(MyProfileLoadedState(
chartPoints: chartPoints,
chartDates: dates,
@@ -231,7 +205,7 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
selectedCity: data['userDetails']['city'],
selectedCountry: data['userDetails']['country'],
selectedActivity: determineActivityLevel(
double.parse(data['userDetails']['activity_coefficient'])),
data['userDetails']['activity_coefficient']),
));
}
} else {