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 {

View File

@@ -182,7 +182,7 @@ class MyProfileScreen extends StatelessWidget {
switch (chartType) {
case 1: // График веса
return GestureDetector(
onTap: _editWeight(context, state),
onTap: () => _editWeight(context, state),
child: Column(children: [
Text(
"weight_chart".tr,
@@ -225,7 +225,7 @@ class MyProfileScreen extends StatelessWidget {
]);
case 3: //График обхватов
return GestureDetector(
onTap: _editCircumference(context, state),
onTap: () => _editCircumference(context, state),
child: Column(children: [
Text(
"circumferences_chart".tr,
@@ -279,10 +279,8 @@ class MyProfileScreen extends StatelessWidget {
);
}
/// Section Widget
_buildChart(
BuildContext context, List<double> chartPoints, List<String>? dates) {
// Определение осей графика
List<FlSpot> spots = [];
for (int i = 0; i < 4; i++) {
spots.add(
@@ -428,7 +426,7 @@ class MyProfileScreen extends StatelessWidget {
};
}
mapSpots() {
List<LineTooltipItem?> Function(List<LineBarSpot>) mapSpots() {
return (touchedSpots) {
return touchedSpots.map((LineBarSpot touchedSpot) {
final textStyle = TextStyle(
@@ -635,7 +633,7 @@ class MyProfileScreen extends StatelessWidget {
);
}
mapTouchedSpots() {
List<LineTooltipItem?> Function(List<LineBarSpot>) mapTouchedSpots() {
return (touchedSpots) {
return touchedSpots.map((LineBarSpot touchedSpot) {
final textStyle = TextStyle(