feat(profile) Added logout function to the App

This commit is contained in:
2024-02-07 13:41:26 +03:00
parent dedcea537e
commit 6ed43a9cff
2 changed files with 20 additions and 8 deletions

View File

@@ -14,8 +14,3 @@ class MyProfileInitialEvent extends MyProfileEvent {
@override
List<Object?> get props => [];
}
class LogoutEvent extends Equatable {
@override
List<Object> get props => [];
}

View File

@@ -13,6 +13,7 @@ import 'package:eatvio_app/widgets/custom_text_form_field.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:hive/hive.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:fl_chart/fl_chart.dart';
@@ -101,7 +102,25 @@ class MyProfileScreen extends StatelessWidget {
ExitButton(
text: "exit".tr,
margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 17.v),
onTap: () {},
onTap: () async {
final box = await Hive.openBox('token');
final token = box.get('token');
final response = await http.post(
Uri.parse(dotenv.env['SERVER_ROOT']! + '/profile/logout'),
headers: {
'Authorization': 'Bearer $token',
},
);
if (response.statusCode == 204) {
print(response.statusCode);
box.delete('token'); // Удаляем токен из Hive
Navigator.pushNamed(
context,
AppRoutes.authScreen,
);
}
},
)
]);
}
@@ -752,13 +771,11 @@ class MyProfileScreen extends StatelessWidget {
}
List<double> _bodyMassIndex(List<double> weightPoints, int height) {
print(weightPoints);
List<double> bmiList = [];
for (double weight in weightPoints) {
double bmi = weight / ((height / 100) * (height / 100));
bmiList.add(bmi);
}
print(bmiList);
return bmiList;
}