Added latest changes and solved the conflicts

This commit is contained in:
Abdullah Alassaf
2024-06-26 22:46:29 +03:00
13 changed files with 151 additions and 67 deletions

View File

@ -10,9 +10,11 @@ import 'package:syncrow_app/features/app_layout/model/space_model.dart';
import 'package:syncrow_app/features/app_layout/view/widgets/app_bar_home_dropdown.dart';
import 'package:syncrow_app/features/auth/model/user_model.dart';
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
import 'package:syncrow_app/features/devices/bloc/ceiling_bloc/ceiling_sensor_state.dart';
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/smart_door_model.dart';
import 'package:syncrow_app/features/devices/model/status_model.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';
@ -20,6 +22,7 @@ import 'package:syncrow_app/features/menu/view/menu_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';
@ -395,6 +398,15 @@ 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}) {

View File

@ -14,6 +14,8 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
import '../device_appbar.dart';
class ACsView extends StatelessWidget {
final DeviceModel? deviceModel;
const ACsView({this.deviceModel, super.key});
@ -34,7 +36,12 @@ class ACsView extends StatelessWidget {
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: AppBar(
appBar: deviceModel != null
? DeviceAppbar(
deviceName: deviceModel!.name!,
deviceUuid: deviceModel!.uuid!,
)
: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: BodyLarge(

View File

@ -20,6 +20,8 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
import '../device_appbar.dart';
class CeilingSensorInterface extends StatelessWidget {
const CeilingSensorInterface({super.key, required this.ceilingSensor});
final DeviceModel ceilingSensor;
@ -49,15 +51,12 @@ class CeilingSensorInterface extends StatelessWidget {
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: BodyLarge(
text: ceilingSensor.name ?? "",
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
appBar:DeviceAppbar(
deviceName: ceilingSensor.name!,
deviceUuid: ceilingSensor.uuid!,
),
body: Container(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,

View File

@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
import 'package:syncrow_app/features/devices/view/widgets/popup_menu_widget.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
class DeviceAppbar extends StatelessWidget implements PreferredSizeWidget {
final String deviceName;
final String deviceUuid;
final double appBarHeight = 56.0;
final void Function()? onPressed;
const DeviceAppbar({super.key, required this.deviceName, required this.deviceUuid,this.onPressed});
@override
Widget build(BuildContext context) {
return AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: BodyLarge(
text: deviceName ?? "",
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
actions: [
IconButton(onPressed: () {
showPopupMenu(context: context, items: [
PopupMenuItem(
onTap: () async {
HomeCubit.getInstance().updateDevice(deviceUuid);
},
value: 'Update',
child: const Text('Update'),
)
]);
}, icon: Icon(Icons.edit))
],
);
}
@override
Size get preferredSize => Size.fromHeight(appBarHeight);
}

View File

@ -6,6 +6,7 @@ import 'package:syncrow_app/features/devices/bloc/gateway_bloc/gateway_bloc.dart
import 'package:syncrow_app/features/devices/bloc/gateway_bloc/gateway_event.dart';
import 'package:syncrow_app/features/devices/bloc/gateway_bloc/gateway_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/device_appbar.dart';
import 'package:syncrow_app/features/devices/view/widgets/room_page_switch.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
@ -37,14 +38,9 @@ class GateWayView extends StatelessWidget {
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: const BodyLarge(
text: 'Gateway',
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
appBar:DeviceAppbar(
deviceName: 'Gateway',
deviceUuid: gatewayObj.uuid!,
),
body: Container(
width: MediaQuery.sizeOf(context).width,

View File

@ -0,0 +1,11 @@
import 'package:flutter/material.dart';
void showPopupMenu(
{required BuildContext context, List<PopupMenuEntry<String>>? items}) async {
await showMenu(
context: context,
position: RelativeRect.fromLTRB( MediaQuery.of(context).size.width/2 , 100, 0, 0),
items: items!,
elevation: 8.0,
);
}

View File

@ -109,7 +109,8 @@ void showDeviceInterface(DeviceModel device, BuildContext context) {
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => DoorInterface(doorLock: device)));
pageBuilder: (context, animation1, animation2) => DoorInterface(doorLock: device))
);
// navigateToInterface(DoorInterface(doorlock: device), context);
break;
case DeviceType.Gateway:

View File

@ -33,9 +33,7 @@ class RoomsSlider extends StatelessWidget {
text: StringsManager.wizard,
style: context.titleMedium.copyWith(
fontSize: 25,
color: HomeCubit.getInstance().selectedRoom == null
? ColorsManager.textPrimaryColor
: ColorsManager.textPrimaryColor.withOpacity(.2),
color: ColorsManager.textPrimaryColor,
),
),
),
@ -46,20 +44,15 @@ class RoomsSlider extends StatelessWidget {
(room) => InkWell(
onTap: () {
HomeCubit.getInstance().roomSliderPageChanged(
HomeCubit.getInstance()
.selectedSpace!
.rooms!
.indexOf(room));
HomeCubit.getInstance().selectedSpace!.rooms!.indexOf(room));
},
child: TitleMedium(
text: room.name!,
style: context.titleMedium.copyWith(
fontSize: 25,
color:
HomeCubit.getInstance().selectedRoom == room
color: HomeCubit.getInstance().selectedRoom == room
? ColorsManager.textPrimaryColor
: ColorsManager.textPrimaryColor
.withOpacity(.2),
: ColorsManager.textPrimaryColor.withOpacity(.2),
),
),
),

View File

@ -6,6 +6,8 @@ import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_eve
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/smart_door_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/device_appbar.dart';
import 'package:syncrow_app/features/devices/view/widgets/popup_menu_widget.dart';
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_button.dart';
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_grid.dart';
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_status_bar.dart';
@ -16,15 +18,16 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart';
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
class DoorInterface extends StatelessWidget {
const DoorInterface({super.key, required this.doorLock});
DoorInterface({super.key, required this.doorLock});
final DeviceModel doorLock;
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => SmartDoorBloc(deviceId: doorLock.uuid ?? '')..add(InitialEvent()),
child: BlocConsumer<SmartDoorBloc, SmartDoorState>(listener: (context, state) {
child: BlocConsumer<SmartDoorBloc, SmartDoorState>(
listener: (context, state) {
if (state is FailedState) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
@ -33,6 +36,7 @@ class DoorInterface extends StatelessWidget {
),
);
}
}, builder: (context, state) {
SmartDoorModel smartDoorModel = SmartDoorModel(
unlockFingerprint: 0,
@ -68,14 +72,9 @@ class DoorInterface extends StatelessWidget {
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: BodyLarge(
text: doorLock.name ?? "",
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
appBar: DeviceAppbar(
deviceName: doorLock.name!,
deviceUuid: doorLock.uuid!,
),
body: Container(
width: MediaQuery.sizeOf(context).width,
@ -126,3 +125,4 @@ class DoorInterface extends StatelessWidget {
);
}
}

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/device_appbar.dart';
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_screen.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/generated/assets.dart';
@ -23,7 +24,12 @@ class ThreeGangInterface extends StatelessWidget {
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: AppBar(
appBar: gangSwitch != null
? DeviceAppbar(
deviceName: gangSwitch!.name!,
deviceUuid: gangSwitch!.uuid!,
)
: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: BodyLarge(

View File

@ -8,6 +8,7 @@ import 'package:syncrow_app/features/devices/bloc/wall_sensor_bloc/wall_sensor_s
import 'package:syncrow_app/features/devices/bloc/wall_sensor_bloc/wall_sensor_event.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/wall_sensor_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/device_appbar.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_medium.dart';
@ -56,14 +57,9 @@ class WallMountedInterface extends StatelessWidget {
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: BodyLarge(
text: deviceModel.name ?? "",
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
appBar: DeviceAppbar(
deviceName: deviceModel.name!,
deviceUuid: deviceModel.uuid!,
),
body: Container(
width: MediaQuery.sizeOf(context).width,

View File

@ -92,6 +92,7 @@ abstract class ApiEndpoints {
static const String addDeviceToRoom = '$baseUrl/device/room';
static const String addDeviceToGroup = '$baseUrl/device/group';
static const String controlDevice = '$baseUrl/device/{deviceUuid}/control';
static const String firmwareDevice = '$baseUrl/device/{deviceUuid}/firmware/{firmwareVersion}';
static const String getDevicesByUserId = '$baseUrl/device/user/{userId}';
//GET

View File

@ -9,6 +9,24 @@ import 'package:syncrow_app/services/api/http_service.dart';
class DevicesAPI {
static final HTTPService _httpService = HTTPService();
static Future<Map<String, dynamic>> firmwareDevice(
{required String deviceId, required String firmwareVersion}) async {
try {
final response = await _httpService.post(
path: ApiEndpoints.firmwareDevice
.replaceAll('{deviceUuid}', deviceId)
.replaceAll('{firmwareVersion}', firmwareVersion),
showServerMessage: false,
expectedResponseModel: (json) {
return json;
},
);
return response;
} catch (e) {
rethrow;
}
}
static Future<Map<String, dynamic>> controlDevice(
DeviceControlModel controlModel, String deviceId) async {
try {