mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +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",
|
||||
"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"
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
}
|
@ -214,4 +214,4 @@ SPEC CHECKSUMS:
|
||||
|
||||
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/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<HomeState> {
|
||||
_instance = null;
|
||||
selectedSpace = null;
|
||||
selectedRoom = null;
|
||||
pageIndex = 0;
|
||||
return super.close();
|
||||
}
|
||||
|
||||
@ -172,8 +172,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
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<HomeState> {
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
@ -209,8 +207,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
@ -230,8 +227,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
@ -241,8 +237,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
@ -275,8 +270,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
};
|
||||
|
||||
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<HomeState> {
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
|
@ -17,9 +17,7 @@ class AppLayout extends StatelessWidget {
|
||||
child: BlocBuilder<HomeCubit, HomeState>(
|
||||
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(),
|
||||
);
|
||||
|
@ -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,
|
||||
|
@ -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<AuthState> {
|
||||
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<AuthState> {
|
||||
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<AuthState> {
|
||||
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<AuthState> {
|
||||
|
||||
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"));
|
||||
|
@ -293,10 +293,8 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
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<DevicesState> {
|
||||
|
||||
//get status for each device
|
||||
//TODO get devices status per page via page controller instead of getting all devices status at once
|
||||
List<DeviceModel> devices =
|
||||
HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!;
|
||||
List<DeviceModel> 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<DevicesState> {
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -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<DeviceModel> lights = [];
|
||||
if (DevicesCubit.allCategories![1].devices != null) {
|
||||
|
@ -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: [
|
||||
|
@ -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<SplashView> createState() => _SplashViewState();
|
||||
}
|
||||
|
||||
class _SplashViewState extends State<SplashView> {
|
||||
@override
|
||||
void initState() {
|
||||
AuthCubit.get(context).getTokenAndValidate();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocConsumer<AuthCubit, AuthState>(
|
||||
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(
|
||||
|
Reference in New Issue
Block a user