mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-17 02:25:16 +00:00
Fixed logout issue
This commit is contained in:
66
.vscode/launch.json
vendored
66
.vscode/launch.json
vendored
@ -5,31 +5,31 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
|
||||||
{
|
// {
|
||||||
"name": "Iphone 15 Pro Max",
|
// "name": "Iphone 15 Pro Max",
|
||||||
"request": "launch",
|
// "request": "launch",
|
||||||
"type": "dart",
|
// "type": "dart",
|
||||||
"deviceId": "0147FC23-3D6C-406A-BE2C-9E67BAF3DA9B"
|
// "deviceId": "0147FC23-3D6C-406A-BE2C-9E67BAF3DA9B"
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
"name": "Faris Iphone ",
|
// "name": "Faris Iphone ",
|
||||||
"request": "launch",
|
// "request": "launch",
|
||||||
"type": "dart",
|
// "type": "dart",
|
||||||
"deviceId": "00008101-00050C1C02FA001E"
|
// "deviceId": "00008101-00050C1C02FA001E"
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
"name": "Iphone 15 Pro",
|
// "name": "Iphone 15 Pro",
|
||||||
"request": "launch",
|
// "request": "launch",
|
||||||
"type": "dart",
|
// "type": "dart",
|
||||||
"deviceId": "B26AF31B-D38E-4485-9628-528E0DB29789"
|
// "deviceId": "B26AF31B-D38E-4485-9628-528E0DB29789"
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
"name": "Iphone SE",
|
// "name": "Iphone SE",
|
||||||
"request": "launch",
|
// "request": "launch",
|
||||||
"type": "dart",
|
// "type": "dart",
|
||||||
"deviceId": "DB3BAF09-EF89-4A31-8DD8-A81DC346CB43",
|
// "deviceId": "A0274205-52D6-48CC-8344-AB4AE3082DE4",
|
||||||
|
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
"name": "syncrow-app",
|
"name": "syncrow-app",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
@ -48,13 +48,13 @@
|
|||||||
"flutterMode": "release"
|
"flutterMode": "release"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"compounds": [
|
// "compounds": [
|
||||||
{
|
// {
|
||||||
"name": "All Device",
|
// "name": "All Device",
|
||||||
"configurations": [
|
// "configurations": [
|
||||||
"Iphone 15 Pro Max",
|
// "Iphone 15 Pro Max",
|
||||||
"Iphone SE"
|
// "Iphone SE"
|
||||||
]
|
// ]
|
||||||
}
|
// }
|
||||||
]
|
// ]
|
||||||
}
|
}
|
@ -214,4 +214,4 @@ SPEC CHECKSUMS:
|
|||||||
|
|
||||||
PODFILE CHECKSUM: cf86fcba3fb3dbd505936bc190bb0b8fe3dd2498
|
PODFILE CHECKSUM: cf86fcba3fb3dbd505936bc190bb0b8fe3dd2498
|
||||||
|
|
||||||
COCOAPODS: 1.15.2
|
COCOAPODS: 1.13.0
|
||||||
|
@ -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/device_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/room_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/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/curtains/curtain_view.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart';
|
||||||
import 'package:syncrow_app/features/menu/view/menu_view.dart';
|
import 'package:syncrow_app/features/menu/view/menu_view.dart';
|
||||||
@ -52,6 +51,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
_instance = null;
|
_instance = null;
|
||||||
selectedSpace = null;
|
selectedSpace = null;
|
||||||
selectedRoom = null;
|
selectedRoom = null;
|
||||||
|
pageIndex = 0;
|
||||||
return super.close();
|
return super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,8 +172,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
size: 25,
|
size: 25,
|
||||||
),
|
),
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
foregroundColor:
|
foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
@ -198,8 +197,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
size: 25,
|
size: 25,
|
||||||
),
|
),
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
foregroundColor:
|
foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
|
||||||
),
|
),
|
||||||
onPressed: () {},
|
onPressed: () {},
|
||||||
),
|
),
|
||||||
@ -209,8 +207,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
size: 25,
|
size: 25,
|
||||||
),
|
),
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
foregroundColor:
|
foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
|
||||||
),
|
),
|
||||||
onPressed: () {},
|
onPressed: () {},
|
||||||
),
|
),
|
||||||
@ -230,8 +227,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
size: 25,
|
size: 25,
|
||||||
),
|
),
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
foregroundColor:
|
foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
|
||||||
),
|
),
|
||||||
onPressed: () {},
|
onPressed: () {},
|
||||||
),
|
),
|
||||||
@ -241,8 +237,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
size: 25,
|
size: 25,
|
||||||
),
|
),
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
foregroundColor:
|
foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
|
||||||
),
|
),
|
||||||
onPressed: () {},
|
onPressed: () {},
|
||||||
),
|
),
|
||||||
@ -275,8 +270,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static var bottomNavItems = [
|
static var bottomNavItems = [
|
||||||
defaultBottomNavBarItem(
|
defaultBottomNavBarItem(icon: Assets.assetsIconsDashboard, label: 'Dashboard'),
|
||||||
icon: Assets.assetsIconsDashboard, label: 'Dashboard'),
|
|
||||||
// defaultBottomNavBarItem(icon: Assets.assetsIconslayout, label: 'Layout'),
|
// defaultBottomNavBarItem(icon: Assets.assetsIconslayout, label: 'Layout'),
|
||||||
defaultBottomNavBarItem(icon: Assets.assetsIconsDevices, label: 'Devices'),
|
defaultBottomNavBarItem(icon: Assets.assetsIconsDevices, label: 'Devices'),
|
||||||
defaultBottomNavBarItem(icon: Assets.assetsIconsRoutines, label: 'Routine'),
|
defaultBottomNavBarItem(icon: Assets.assetsIconsRoutines, label: 'Routine'),
|
||||||
@ -301,8 +295,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BottomNavigationBarItem defaultBottomNavBarItem(
|
BottomNavigationBarItem defaultBottomNavBarItem({required String icon, required String label}) {
|
||||||
{required String icon, required String label}) {
|
|
||||||
return BottomNavigationBarItem(
|
return BottomNavigationBarItem(
|
||||||
icon: SvgPicture.asset(icon),
|
icon: SvgPicture.asset(icon),
|
||||||
activeIcon: SvgPicture.asset(
|
activeIcon: SvgPicture.asset(
|
||||||
|
@ -17,9 +17,7 @@ class AppLayout extends StatelessWidget {
|
|||||||
child: BlocBuilder<HomeCubit, HomeState>(
|
child: BlocBuilder<HomeCubit, HomeState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
appBar: HomeCubit.getInstance().spaces != null
|
appBar: HomeCubit.getInstance().spaces != null ? const DefaultAppBar() : null,
|
||||||
? const DefaultAppBar()
|
|
||||||
: null,
|
|
||||||
bottomNavBar: const DefaultNavBar(),
|
bottomNavBar: const DefaultNavBar(),
|
||||||
child: const AppBody(),
|
child: const AppBody(),
|
||||||
);
|
);
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
|
||||||
|
|
||||||
class AppBody extends StatelessWidget {
|
class AppBody extends StatelessWidget {
|
||||||
const AppBody({
|
const AppBody({
|
||||||
super.key,
|
super.key,
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.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/login_with_email_model.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/token.dart';
|
import 'package:syncrow_app/features/auth/model/token.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/user_model.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';
|
part 'auth_state.dart';
|
||||||
|
|
||||||
class AuthCubit extends Cubit<AuthState> {
|
class AuthCubit extends Cubit<AuthState> {
|
||||||
AuthCubit() : super(AuthInitial()) {
|
AuthCubit() : super(AuthInitial());
|
||||||
getTokenAndValidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
static AuthCubit get(context) => BlocProvider.of(context);
|
static AuthCubit get(context) => BlocProvider.of(context);
|
||||||
|
|
||||||
final TextEditingController emailController = TextEditingController();
|
final TextEditingController emailController = TextEditingController();
|
||||||
@ -108,8 +103,7 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
if (token.accessTokenIsNotEmpty) {
|
if (token.accessTokenIsNotEmpty) {
|
||||||
debugPrint('token: ${token.accessToken}');
|
debugPrint('token: ${token.accessToken}');
|
||||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||||
await storage.write(
|
await storage.write(key: Token.loginAccessTokenKey, value: token.accessToken);
|
||||||
key: Token.loginAccessTokenKey, value: token.accessToken);
|
|
||||||
|
|
||||||
const FlutterSecureStorage().write(
|
const FlutterSecureStorage().write(
|
||||||
key: UserModel.userUuidKey,
|
key: UserModel.userUuidKey,
|
||||||
@ -129,9 +123,10 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
try {
|
try {
|
||||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||||
await storage.delete(key: Token.loginAccessTokenKey);
|
await storage.delete(key: Token.loginAccessTokenKey);
|
||||||
NavigationService.navigatorKey.currentState!
|
NavigationService.navigatorKey.currentState!.pushNamedAndRemoveUntil(
|
||||||
.popAndPushNamed(Routes.authLogin);
|
Routes.splash,
|
||||||
emit(AuthLogoutSuccess());
|
(Route route) => false,
|
||||||
|
);
|
||||||
} catch (failure) {
|
} catch (failure) {
|
||||||
emit(AuthLogoutError(message: failure.toString()));
|
emit(AuthLogoutError(message: failure.toString()));
|
||||||
return;
|
return;
|
||||||
@ -140,8 +135,7 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
|
|
||||||
getTokenAndValidate() async {
|
getTokenAndValidate() async {
|
||||||
emit(AuthTokenLoading());
|
emit(AuthTokenLoading());
|
||||||
final value =
|
final value = await const FlutterSecureStorage().read(key: Token.loginAccessTokenKey);
|
||||||
await const FlutterSecureStorage().read(key: Token.loginAccessTokenKey);
|
|
||||||
|
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
emit(AuthTokenError(message: "Token not found"));
|
emit(AuthTokenError(message: "Token not found"));
|
||||||
|
@ -293,10 +293,8 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
if (roomId == null) return;
|
if (roomId == null) return;
|
||||||
|
|
||||||
emitSafe(GetDevicesLoading());
|
emitSafe(GetDevicesLoading());
|
||||||
int roomIndex = HomeCubit.getInstance()
|
int roomIndex =
|
||||||
.selectedSpace!
|
HomeCubit.getInstance().selectedSpace!.rooms!.indexWhere((element) => element.id == roomId);
|
||||||
.rooms!
|
|
||||||
.indexWhere((element) => element.id == roomId);
|
|
||||||
try {
|
try {
|
||||||
HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices =
|
HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices =
|
||||||
await DevicesAPI.getDevicesByRoomId(roomId);
|
await DevicesAPI.getDevicesByRoomId(roomId);
|
||||||
@ -308,8 +306,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
|
|
||||||
//get status for each device
|
//get status for each device
|
||||||
//TODO get devices status per page via page controller instead of getting all devices status at once
|
//TODO get devices status per page via page controller instead of getting all devices status at once
|
||||||
List<DeviceModel> devices =
|
List<DeviceModel> devices = HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!;
|
||||||
HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!;
|
|
||||||
if (devices.isNotEmpty) {
|
if (devices.isNotEmpty) {
|
||||||
for (var device in devices) {
|
for (var device in devices) {
|
||||||
fetchDevicesStatues(device.uuid!, roomIndex);
|
fetchDevicesStatues(device.uuid!, roomIndex);
|
||||||
@ -334,11 +331,8 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
emitSafe(GetDeviceStatusError(e.toString()));
|
emitSafe(GetDeviceStatusError(e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HomeCubit.getInstance()
|
HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices![deviceIndex].status =
|
||||||
.selectedSpace!
|
statuses;
|
||||||
.rooms![roomIndex]
|
|
||||||
.devices![deviceIndex]
|
|
||||||
.status = statuses;
|
|
||||||
emitSafe(GetDeviceStatusSuccess(code: code));
|
emitSafe(GetDeviceStatusSuccess(code: code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,7 @@ class LightsView extends StatelessWidget {
|
|||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
DeviceModel? selectedLight;
|
DeviceModel? selectedLight;
|
||||||
if (DevicesCubit.getInstance().getSelectedDevice() is DeviceModel) {
|
if (DevicesCubit.getInstance().getSelectedDevice() is DeviceModel) {
|
||||||
selectedLight =
|
selectedLight = DevicesCubit.getInstance().getSelectedDevice() as DeviceModel;
|
||||||
DevicesCubit.getInstance().getSelectedDevice() as DeviceModel;
|
|
||||||
}
|
}
|
||||||
List<DeviceModel> lights = [];
|
List<DeviceModel> lights = [];
|
||||||
if (DevicesCubit.allCategories![1].devices != null) {
|
if (DevicesCubit.allCategories![1].devices != null) {
|
||||||
|
@ -2,13 +2,10 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/auth/bloc/auth_cubit.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/bloc/menu_cubit.dart';
|
||||||
|
|
||||||
import 'package:syncrow_app/features/menu/view/widgets/menu_list.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/menu/view/widgets/profile/profile_tab.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/default_container.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/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/context_extension.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
|
|
||||||
@ -38,8 +35,6 @@ class MenuView extends StatelessWidget {
|
|||||||
InkWell(
|
InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
AuthCubit.get(context).logout();
|
AuthCubit.get(context).logout();
|
||||||
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
||||||
Routes.authLogin, (route) => false);
|
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
@ -7,16 +7,26 @@ import 'package:syncrow_app/generated/assets.dart';
|
|||||||
import 'package:syncrow_app/navigation/routing_constants.dart';
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||||
import 'package:syncrow_app/utils/helpers/custom_page_route.dart';
|
import 'package:syncrow_app/utils/helpers/custom_page_route.dart';
|
||||||
|
|
||||||
class SplashView extends StatelessWidget {
|
class SplashView extends StatefulWidget {
|
||||||
const SplashView({super.key});
|
const SplashView({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SplashView> createState() => _SplashViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SplashViewState extends State<SplashView> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
AuthCubit.get(context).getTokenAndValidate();
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocConsumer<AuthCubit, AuthState>(
|
return BlocConsumer<AuthCubit, AuthState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is AuthTokenSuccess) {
|
if (state is AuthTokenSuccess) {
|
||||||
Navigator.pushNamedAndRemoveUntil(
|
Navigator.pushNamedAndRemoveUntil(context, Routes.homeRoute, (route) => false);
|
||||||
context, Routes.homeRoute, (route) => false);
|
|
||||||
} else if (state is AuthTokenError) {
|
} else if (state is AuthTokenError) {
|
||||||
Future.delayed(const Duration(seconds: 1), () {
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
Navigator.pushReplacement(
|
Navigator.pushReplacement(
|
||||||
|
Reference in New Issue
Block a user