mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-23 11:57:54 +00:00
Fixed logout issue
This commit is contained in:
@@ -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