mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 21:34:54 +00:00
Added latest changes from dev and solved conflicts
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
@ -22,6 +21,7 @@ import 'package:syncrow_app/features/scene/view/create_scene_view.dart';
|
||||
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/navigation/navigation_service.dart';
|
||||
import 'package:syncrow_app/services/api/devices_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';
|
||||
@ -63,12 +63,9 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
selectedSpace = null;
|
||||
selectedRoom = null;
|
||||
pageIndex = 0;
|
||||
OneSignal.User.pushSubscription
|
||||
.removeObserver((stateChanges) => oneSignalSubscriptionObserver);
|
||||
OneSignal.Notifications.removePermissionObserver(
|
||||
(permission) => oneSignalPermissionObserver);
|
||||
OneSignal.Notifications.removeClickListener(
|
||||
(event) => oneSignalClickListenerObserver);
|
||||
OneSignal.User.pushSubscription.removeObserver((stateChanges) => oneSignalSubscriptionObserver);
|
||||
OneSignal.Notifications.removePermissionObserver((permission) => oneSignalPermissionObserver);
|
||||
OneSignal.Notifications.removeClickListener((event) => oneSignalClickListenerObserver);
|
||||
return super.close();
|
||||
}
|
||||
|
||||
@ -110,9 +107,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
return;
|
||||
}
|
||||
|
||||
var userUuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ??
|
||||
'';
|
||||
var userUuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ?? '';
|
||||
if (userUuid.isNotEmpty) {
|
||||
await OneSignal.login(userUuid);
|
||||
}
|
||||
@ -120,24 +115,21 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
await OneSignal.User.pushSubscription.optIn();
|
||||
|
||||
//this function will be called once a user is subscribed
|
||||
oneSignalSubscriptionObserver =
|
||||
OneSignal.User.pushSubscription.addObserver((state) async {
|
||||
oneSignalSubscriptionObserver = OneSignal.User.pushSubscription.addObserver((state) async {
|
||||
if (state.current.optedIn) {
|
||||
await _sendSubscriptionId();
|
||||
}
|
||||
});
|
||||
|
||||
// Send the player id when a user allows notifications
|
||||
oneSignalPermissionObserver =
|
||||
OneSignal.Notifications.addPermissionObserver((state) async {
|
||||
oneSignalPermissionObserver = OneSignal.Notifications.addPermissionObserver((state) async {
|
||||
await _sendSubscriptionId();
|
||||
});
|
||||
|
||||
//check if the player id is sent, if not send it again
|
||||
await _sendSubscriptionId();
|
||||
|
||||
oneSignalClickListenerObserver =
|
||||
OneSignal.Notifications.addClickListener((event) async {
|
||||
oneSignalClickListenerObserver = OneSignal.Notifications.addClickListener((event) async {
|
||||
//Once the user clicks on the notification
|
||||
});
|
||||
} catch (err) {
|
||||
@ -224,9 +216,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
|
||||
Future<bool> joinAUnit(String code) async {
|
||||
try {
|
||||
var uuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ??
|
||||
'';
|
||||
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ?? '';
|
||||
Map<String, String> body = {'userUuid': uuid, 'inviteCode': code};
|
||||
|
||||
final success = await SpacesAPI.joinUnit(body);
|
||||
@ -280,30 +270,29 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
|
||||
static Map<String, List<Widget>> appBarActions = {
|
||||
'Dashboard': [
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
NavigationService.navigatorKey.currentContext!,
|
||||
CustomPageRoute(
|
||||
builder: (context) => CurtainView(
|
||||
curtain: DeviceModel(
|
||||
name: "Curtain",
|
||||
status: [StatusModel(code: "awd", value: 1)],
|
||||
productType: DeviceType.Curtain,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
// IconButton(
|
||||
// icon: const Icon(
|
||||
// Icons.add,
|
||||
// size: 25,
|
||||
// ),
|
||||
// style: ButtonStyle(
|
||||
// foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
// ),
|
||||
// onPressed: () {
|
||||
// Navigator.push(
|
||||
// NavigationService.navigatorKey.currentContext!,
|
||||
// CustomPageRoute(
|
||||
// builder: (context) => CurtainView(
|
||||
// curtain: DeviceModel(
|
||||
// name: "Curtain",
|
||||
// status: [StatusModel(code: "awd", value: 1)],
|
||||
// productType: DeviceType.Curtain,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
],
|
||||
'Devices': [
|
||||
//TODO: to be checked
|
||||
@ -345,8 +334,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
size: 32,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
@ -363,8 +351,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
size: 28,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
@ -397,8 +384,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'),
|
||||
@ -421,10 +407,18 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
|
||||
emitSafe(NavChangePage());
|
||||
}
|
||||
|
||||
void updateDevice(String deviceId) async {
|
||||
try {
|
||||
final response = await DevicesAPI.firmwareDevice(deviceId: deviceId, firmwareVersion: '0');
|
||||
if (response['success'] ?? false) {
|
||||
CustomSnackBar.displaySnackBar('No updates available');
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user