Merged with SP-203

This commit is contained in:
Abdullah Alassaf
2024-07-25 14:15:06 +03:00
46 changed files with 1973 additions and 811 deletions

View File

@ -27,6 +27,7 @@ import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/navigation/navigation_service.dart';
import 'package:syncrow_app/navigation/routing_constants.dart';
import 'package:syncrow_app/services/api/devices_api.dart';
import 'package:syncrow_app/services/api/profile_api.dart';
import 'package:syncrow_app/services/api/spaces_api.dart';
import 'package:syncrow_app/utils/helpers/custom_page_route.dart';
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
@ -38,6 +39,7 @@ part 'home_state.dart';
class HomeCubit extends Cubit<HomeState> {
HomeCubit._() : super(HomeInitial()) {
checkIfNotificationPermissionGranted();
fetchUserInfo();
if (selectedSpace == null) {
fetchUnitsByUserId();
// .then((value) {
@ -47,7 +49,7 @@ class HomeCubit extends Cubit<HomeState> {
// });
}
}
static UserModel? user;
static HomeCubit? _instance;
static HomeCubit getInstance() {
// If an instance already exists, return it
@ -55,6 +57,18 @@ class HomeCubit extends Cubit<HomeState> {
return _instance!;
}
Future fetchUserInfo() async {
try {
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
user = await ProfileApi().fetchUserInfo(uuid);
emit(HomeUserInfoLoaded(user!)); // Emit state after fetching user info
} catch (e) {
return;
}
}
void emitSafe(HomeState newState) {
final cubit = this;
if (!cubit.isClosed) {

View File

@ -58,3 +58,9 @@ class RoomSelected extends HomeState {
class RoomUnSelected extends HomeState {}
class NavChangePage extends HomeState {}
// Define new state classes
class HomeUserInfoLoaded extends HomeState {
final UserModel user;
HomeUserInfoLoaded(this.user);
}