From 0f75c3def169c0ff56c22e54e1df44bc7747ac7e Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Sat, 18 May 2024 23:45:23 +0300 Subject: [PATCH] Fixed logout issue --- .vscode/launch.json | 66 +++++++++---------- ios/Podfile.lock | 2 +- lib/features/app_layout/bloc/home_cubit.dart | 23 +++---- lib/features/app_layout/view/app_layout.dart | 4 +- .../app_layout/view/widgets/app_body.dart | 2 - lib/features/auth/bloc/auth_cubit.dart | 20 ++---- lib/features/devices/bloc/devices_cubit.dart | 16 ++--- .../view/widgets/lights/lights_view.dart | 3 +- lib/features/menu/view/menu_view.dart | 5 -- lib/features/splash/view/splash_view.dart | 16 ++++- 10 files changed, 69 insertions(+), 88 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ea8d313..3391554 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,31 +5,31 @@ "version": "0.2.0", "configurations": [ - { - "name": "Iphone 15 Pro Max", - "request": "launch", - "type": "dart", - "deviceId": "0147FC23-3D6C-406A-BE2C-9E67BAF3DA9B" - }, - { - "name": "Faris Iphone ", - "request": "launch", - "type": "dart", - "deviceId": "00008101-00050C1C02FA001E" - }, - { - "name": "Iphone 15 Pro", - "request": "launch", - "type": "dart", - "deviceId": "B26AF31B-D38E-4485-9628-528E0DB29789" - }, - { - "name": "Iphone SE", - "request": "launch", - "type": "dart", - "deviceId": "DB3BAF09-EF89-4A31-8DD8-A81DC346CB43", + // { + // "name": "Iphone 15 Pro Max", + // "request": "launch", + // "type": "dart", + // "deviceId": "0147FC23-3D6C-406A-BE2C-9E67BAF3DA9B" + // }, + // { + // "name": "Faris Iphone ", + // "request": "launch", + // "type": "dart", + // "deviceId": "00008101-00050C1C02FA001E" + // }, + // { + // "name": "Iphone 15 Pro", + // "request": "launch", + // "type": "dart", + // "deviceId": "B26AF31B-D38E-4485-9628-528E0DB29789" + // }, + // { + // "name": "Iphone SE", + // "request": "launch", + // "type": "dart", + // "deviceId": "A0274205-52D6-48CC-8344-AB4AE3082DE4", - }, + // }, { "name": "syncrow-app", "request": "launch", @@ -48,13 +48,13 @@ "flutterMode": "release" } ], - "compounds": [ - { - "name": "All Device", - "configurations": [ - "Iphone 15 Pro Max", - "Iphone SE" - ] - } - ] + // "compounds": [ + // { + // "name": "All Device", + // "configurations": [ + // "Iphone 15 Pro Max", + // "Iphone SE" + // ] + // } + // ] } \ No newline at end of file diff --git a/ios/Podfile.lock b/ios/Podfile.lock index c74adc2..20555ff 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -214,4 +214,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: cf86fcba3fb3dbd505936bc190bb0b8fe3dd2498 -COCOAPODS: 1.15.2 +COCOAPODS: 1.13.0 diff --git a/lib/features/app_layout/bloc/home_cubit.dart b/lib/features/app_layout/bloc/home_cubit.dart index 0a88244..976e6b9 100644 --- a/lib/features/app_layout/bloc/home_cubit.dart +++ b/lib/features/app_layout/bloc/home_cubit.dart @@ -8,7 +8,6 @@ import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/room_model.dart'; import 'package:syncrow_app/features/devices/model/status_model.dart'; -import 'package:syncrow_app/features/devices/view/widgets/curtains/blind_view.dart'; import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_view.dart'; import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart'; import 'package:syncrow_app/features/menu/view/menu_view.dart'; @@ -52,6 +51,7 @@ class HomeCubit extends Cubit { _instance = null; selectedSpace = null; selectedRoom = null; + pageIndex = 0; return super.close(); } @@ -172,8 +172,7 @@ class HomeCubit extends Cubit { size: 25, ), style: ButtonStyle( - foregroundColor: - MaterialStateProperty.all(ColorsManager.textPrimaryColor), + foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor), ), onPressed: () { Navigator.push( @@ -198,8 +197,7 @@ class HomeCubit extends Cubit { size: 25, ), style: ButtonStyle( - foregroundColor: - MaterialStateProperty.all(ColorsManager.textPrimaryColor), + foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor), ), onPressed: () {}, ), @@ -209,8 +207,7 @@ class HomeCubit extends Cubit { size: 25, ), style: ButtonStyle( - foregroundColor: - MaterialStateProperty.all(ColorsManager.textPrimaryColor), + foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor), ), onPressed: () {}, ), @@ -230,8 +227,7 @@ class HomeCubit extends Cubit { size: 25, ), style: ButtonStyle( - foregroundColor: - MaterialStateProperty.all(ColorsManager.textPrimaryColor), + foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor), ), onPressed: () {}, ), @@ -241,8 +237,7 @@ class HomeCubit extends Cubit { size: 25, ), style: ButtonStyle( - foregroundColor: - MaterialStateProperty.all(ColorsManager.textPrimaryColor), + foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor), ), onPressed: () {}, ), @@ -275,8 +270,7 @@ class HomeCubit extends Cubit { }; static var bottomNavItems = [ - defaultBottomNavBarItem( - icon: Assets.assetsIconsDashboard, label: 'Dashboard'), + defaultBottomNavBarItem(icon: Assets.assetsIconsDashboard, label: 'Dashboard'), // defaultBottomNavBarItem(icon: Assets.assetsIconslayout, label: 'Layout'), defaultBottomNavBarItem(icon: Assets.assetsIconsDevices, label: 'Devices'), defaultBottomNavBarItem(icon: Assets.assetsIconsRoutines, label: 'Routine'), @@ -301,8 +295,7 @@ class HomeCubit extends Cubit { } } -BottomNavigationBarItem defaultBottomNavBarItem( - {required String icon, required String label}) { +BottomNavigationBarItem defaultBottomNavBarItem({required String icon, required String label}) { return BottomNavigationBarItem( icon: SvgPicture.asset(icon), activeIcon: SvgPicture.asset( diff --git a/lib/features/app_layout/view/app_layout.dart b/lib/features/app_layout/view/app_layout.dart index 93e486d..214cce2 100644 --- a/lib/features/app_layout/view/app_layout.dart +++ b/lib/features/app_layout/view/app_layout.dart @@ -17,9 +17,7 @@ class AppLayout extends StatelessWidget { child: BlocBuilder( builder: (context, state) { return DefaultScaffold( - appBar: HomeCubit.getInstance().spaces != null - ? const DefaultAppBar() - : null, + appBar: HomeCubit.getInstance().spaces != null ? const DefaultAppBar() : null, bottomNavBar: const DefaultNavBar(), child: const AppBody(), ); diff --git a/lib/features/app_layout/view/widgets/app_body.dart b/lib/features/app_layout/view/widgets/app_body.dart index a8693f2..f902db1 100644 --- a/lib/features/app_layout/view/widgets/app_body.dart +++ b/lib/features/app_layout/view/widgets/app_body.dart @@ -1,9 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; - import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; - class AppBody extends StatelessWidget { const AppBody({ super.key, diff --git a/lib/features/auth/bloc/auth_cubit.dart b/lib/features/auth/bloc/auth_cubit.dart index 5dfb9d9..c084048 100644 --- a/lib/features/auth/bloc/auth_cubit.dart +++ b/lib/features/auth/bloc/auth_cubit.dart @@ -1,8 +1,6 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; - import 'package:syncrow_app/features/auth/model/login_with_email_model.dart'; import 'package:syncrow_app/features/auth/model/token.dart'; import 'package:syncrow_app/features/auth/model/user_model.dart'; @@ -13,10 +11,7 @@ import 'package:syncrow_app/services/api/authentication_api.dart'; part 'auth_state.dart'; class AuthCubit extends Cubit { - AuthCubit() : super(AuthInitial()) { - getTokenAndValidate(); - } - + AuthCubit() : super(AuthInitial()); static AuthCubit get(context) => BlocProvider.of(context); final TextEditingController emailController = TextEditingController(); @@ -108,8 +103,7 @@ class AuthCubit extends Cubit { if (token.accessTokenIsNotEmpty) { debugPrint('token: ${token.accessToken}'); FlutterSecureStorage storage = const FlutterSecureStorage(); - await storage.write( - key: Token.loginAccessTokenKey, value: token.accessToken); + await storage.write(key: Token.loginAccessTokenKey, value: token.accessToken); const FlutterSecureStorage().write( key: UserModel.userUuidKey, @@ -129,9 +123,10 @@ class AuthCubit extends Cubit { try { FlutterSecureStorage storage = const FlutterSecureStorage(); await storage.delete(key: Token.loginAccessTokenKey); - NavigationService.navigatorKey.currentState! - .popAndPushNamed(Routes.authLogin); - emit(AuthLogoutSuccess()); + NavigationService.navigatorKey.currentState!.pushNamedAndRemoveUntil( + Routes.splash, + (Route route) => false, + ); } catch (failure) { emit(AuthLogoutError(message: failure.toString())); return; @@ -140,8 +135,7 @@ class AuthCubit extends Cubit { getTokenAndValidate() async { emit(AuthTokenLoading()); - final value = - await const FlutterSecureStorage().read(key: Token.loginAccessTokenKey); + final value = await const FlutterSecureStorage().read(key: Token.loginAccessTokenKey); if (value == null || value.isEmpty) { emit(AuthTokenError(message: "Token not found")); diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index c362cc6..f0635c0 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -293,10 +293,8 @@ class DevicesCubit extends Cubit { if (roomId == null) return; emitSafe(GetDevicesLoading()); - int roomIndex = HomeCubit.getInstance() - .selectedSpace! - .rooms! - .indexWhere((element) => element.id == roomId); + int roomIndex = + HomeCubit.getInstance().selectedSpace!.rooms!.indexWhere((element) => element.id == roomId); try { HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices = await DevicesAPI.getDevicesByRoomId(roomId); @@ -308,8 +306,7 @@ class DevicesCubit extends Cubit { //get status for each device //TODO get devices status per page via page controller instead of getting all devices status at once - List devices = - HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!; + List devices = HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!; if (devices.isNotEmpty) { for (var device in devices) { fetchDevicesStatues(device.uuid!, roomIndex); @@ -334,11 +331,8 @@ class DevicesCubit extends Cubit { emitSafe(GetDeviceStatusError(e.toString())); return; } - HomeCubit.getInstance() - .selectedSpace! - .rooms![roomIndex] - .devices![deviceIndex] - .status = statuses; + HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices![deviceIndex].status = + statuses; emitSafe(GetDeviceStatusSuccess(code: code)); } diff --git a/lib/features/devices/view/widgets/lights/lights_view.dart b/lib/features/devices/view/widgets/lights/lights_view.dart index 0ff37eb..0e45ed4 100644 --- a/lib/features/devices/view/widgets/lights/lights_view.dart +++ b/lib/features/devices/view/widgets/lights/lights_view.dart @@ -20,8 +20,7 @@ class LightsView extends StatelessWidget { builder: (context, state) { DeviceModel? selectedLight; if (DevicesCubit.getInstance().getSelectedDevice() is DeviceModel) { - selectedLight = - DevicesCubit.getInstance().getSelectedDevice() as DeviceModel; + selectedLight = DevicesCubit.getInstance().getSelectedDevice() as DeviceModel; } List lights = []; if (DevicesCubit.allCategories![1].devices != null) { diff --git a/lib/features/menu/view/menu_view.dart b/lib/features/menu/view/menu_view.dart index a6bfb9d..0d3dc83 100644 --- a/lib/features/menu/view/menu_view.dart +++ b/lib/features/menu/view/menu_view.dart @@ -2,13 +2,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart'; import 'package:syncrow_app/features/menu/bloc/menu_cubit.dart'; - import 'package:syncrow_app/features/menu/view/widgets/menu_list.dart'; import 'package:syncrow_app/features/menu/view/widgets/profile/profile_tab.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart'; - -import 'package:syncrow_app/navigation/routing_constants.dart'; import 'package:syncrow_app/utils/context_extension.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; @@ -38,8 +35,6 @@ class MenuView extends StatelessWidget { InkWell( onTap: () { AuthCubit.get(context).logout(); - Navigator.of(context).pushNamedAndRemoveUntil( - Routes.authLogin, (route) => false); }, child: Row( children: [ diff --git a/lib/features/splash/view/splash_view.dart b/lib/features/splash/view/splash_view.dart index e2d7b7c..26b23df 100644 --- a/lib/features/splash/view/splash_view.dart +++ b/lib/features/splash/view/splash_view.dart @@ -7,16 +7,26 @@ import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/navigation/routing_constants.dart'; import 'package:syncrow_app/utils/helpers/custom_page_route.dart'; -class SplashView extends StatelessWidget { +class SplashView extends StatefulWidget { const SplashView({super.key}); + @override + State createState() => _SplashViewState(); +} + +class _SplashViewState extends State { + @override + void initState() { + AuthCubit.get(context).getTokenAndValidate(); + super.initState(); + } + @override Widget build(BuildContext context) { return BlocConsumer( listener: (context, state) { if (state is AuthTokenSuccess) { - Navigator.pushNamedAndRemoveUntil( - context, Routes.homeRoute, (route) => false); + Navigator.pushNamedAndRemoveUntil(context, Routes.homeRoute, (route) => false); } else if (state is AuthTokenError) { Future.delayed(const Duration(seconds: 1), () { Navigator.pushReplacement(