From 6ed43a9cff93b89bba788f945864eb5b54ed01df Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 7 Feb 2024 13:41:26 +0300 Subject: [PATCH] feat(profile) Added logout function to the App --- .../bloc/my_profile_event.dart | 5 ---- .../my_profile_screen/my_profile_screen.dart | 23 ++++++++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/presentation/profile/my_profile_screen/bloc/my_profile_event.dart b/lib/presentation/profile/my_profile_screen/bloc/my_profile_event.dart index 0eae41e5..99c025a4 100644 --- a/lib/presentation/profile/my_profile_screen/bloc/my_profile_event.dart +++ b/lib/presentation/profile/my_profile_screen/bloc/my_profile_event.dart @@ -14,8 +14,3 @@ class MyProfileInitialEvent extends MyProfileEvent { @override List get props => []; } - -class LogoutEvent extends Equatable { - @override - List get props => []; -} diff --git a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart index 54262f32..3b65469e 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -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 _bodyMassIndex(List weightPoints, int height) { - print(weightPoints); List bmiList = []; for (double weight in weightPoints) { double bmi = weight / ((height / 100) * (height / 100)); bmiList.add(bmi); } - print(bmiList); return bmiList; }