From f8e8591d13a372752f8ff3af631b2990b9f1d1d7 Mon Sep 17 00:00:00 2001 From: Mohammad Salameh Date: Thu, 7 Mar 2024 14:53:13 +0300 Subject: [PATCH] Implemented room device interface (AC only) --- .../app_layout/bloc/spaces_cubit.dart | 15 +- lib/features/devices/bloc/devices_cubit.dart | 30 +-- .../devices/model/device_category_model.dart | 10 +- lib/features/devices/model/device_model.dart | 29 ++- .../view/widgets/ACs/ac_interface.dart | 88 +++++-- .../widgets/ACs/ac_interface_temp_unit.dart | 219 +++++++++--------- .../devices/view/widgets/room_page.dart | 69 +----- .../view/widgets/room_page_switch.dart | 86 +++++++ .../shared_widgets/custom_switch.dart | 32 ++- lib/generated/assets.dart | 2 + lib/services/api/http_service.dart | 12 +- lib/utils/resource_manager/constants.dart | 9 + 12 files changed, 357 insertions(+), 244 deletions(-) create mode 100644 lib/features/devices/view/widgets/room_page_switch.dart diff --git a/lib/features/app_layout/bloc/spaces_cubit.dart b/lib/features/app_layout/bloc/spaces_cubit.dart index b64970a..c090e93 100644 --- a/lib/features/app_layout/bloc/spaces_cubit.dart +++ b/lib/features/app_layout/bloc/spaces_cubit.dart @@ -12,6 +12,7 @@ import 'package:syncrow_app/features/devices/view/widgets/gateway/gateway_view.d import 'package:syncrow_app/features/devices/view/widgets/lights/lights_view.dart'; import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_view.dart'; import 'package:syncrow_app/generated/assets.dart'; +import 'package:syncrow_app/utils/resource_manager/constants.dart'; part 'spaces_state.dart'; @@ -36,7 +37,7 @@ class SpacesCubit extends Cubit { fanSpeed: 0, tempMode: 0, coolTo: 20, - type: '', + type: DeviceType.AC, image: '', timer: null, bounds: Bounds( @@ -60,7 +61,7 @@ class SpacesCubit extends Cubit { brightness: 20, lightingMode: 1, timer: null, - type: '', + type: DeviceType.Lights, image: '', recentColors: [ 0xFF83D9FF, @@ -89,7 +90,7 @@ class SpacesCubit extends Cubit { id: "1", name: "Living Room Curtain", status: false, - type: '', + type: DeviceType.Curtain, image: '', timer: null, ), @@ -118,7 +119,7 @@ class SpacesCubit extends Cubit { fanSpeed: 0, tempMode: 0, coolTo: 20, - type: '', + type: DeviceType.AC, image: '', timer: null, bounds: Bounds( @@ -142,7 +143,7 @@ class SpacesCubit extends Cubit { brightness: 20, lightingMode: 1, timer: null, - type: '', + type: DeviceType.Lights, image: '', recentColors: [ 0xFF83D9FF, @@ -171,7 +172,7 @@ class SpacesCubit extends Cubit { id: "1", name: "Living Room Curtain", status: false, - type: '', + type: DeviceType.Curtain, image: '', timer: null, ), @@ -229,7 +230,6 @@ class SpacesCubit extends Cubit { unselectRoom(); } else { selectedRoom = selectedSpace.rooms[index - 1]; - print(selectedRoom!.name); } emit(RoomSelected(selectedRoom!)); } @@ -245,7 +245,6 @@ class SpacesCubit extends Cubit { unselectRoom(); } else { selectedRoom = selectedSpace.rooms[index - 1]; - print(selectedRoom!.name); } emit(RoomSelected(selectedRoom!)); } diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index 1c48e39..58eb672 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -2,17 +2,17 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/devices/model/ac_model.dart'; import 'package:syncrow_app/features/devices/model/curtain_model.dart'; +import 'package:syncrow_app/features/devices/model/device_category_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/light_model.dart'; +import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_view.dart'; import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_view.dart'; import 'package:syncrow_app/features/devices/view/widgets/gateway/gateway_view.dart'; +import 'package:syncrow_app/features/devices/view/widgets/lights/lights_view.dart'; import 'package:syncrow_app/features/devices/view/widgets/screens/screens_view.dart'; import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_view.dart'; import 'package:syncrow_app/generated/assets.dart'; - -import '../model/device_category_model.dart'; -import '../view/widgets/ACs/acs_view.dart'; -import '../view/widgets/lights/lights_view.dart'; +import 'package:syncrow_app/utils/resource_manager/constants.dart'; part 'devices_state.dart'; @@ -32,7 +32,7 @@ class DevicesCubit extends Cubit { fanSpeed: 0, tempMode: 0, coolTo: 20, - type: '', + type: DeviceType.AC, image: '', timer: null, bounds: Bounds( @@ -48,7 +48,7 @@ class DevicesCubit extends Cubit { fanSpeed: 0, tempMode: 0, coolTo: 20, - type: '', + type: DeviceType.AC, image: '', timer: null, bounds: Bounds( @@ -64,7 +64,7 @@ class DevicesCubit extends Cubit { fanSpeed: 0, tempMode: 0, coolTo: 20, - type: '', + type: DeviceType.AC, image: '', timer: null, bounds: Bounds( @@ -80,7 +80,7 @@ class DevicesCubit extends Cubit { fanSpeed: 0, tempMode: 0, coolTo: 20, - type: '', + type: DeviceType.AC, image: '', timer: null, bounds: Bounds( @@ -104,7 +104,7 @@ class DevicesCubit extends Cubit { brightness: 20, lightingMode: 1, timer: null, - type: '', + type: DeviceType.Lights, image: '', recentColors: [ 0xFF83D9FF, @@ -121,7 +121,7 @@ class DevicesCubit extends Cubit { brightness: 40, lightingMode: 1, timer: null, - type: '', + type: DeviceType.Lights, image: '', recentColors: [ 0xFF83D9FF, @@ -138,7 +138,7 @@ class DevicesCubit extends Cubit { brightness: 60, lightingMode: 1, timer: null, - type: '', + type: DeviceType.Lights, image: '', recentColors: [ 0xFF83D9FF, @@ -155,7 +155,7 @@ class DevicesCubit extends Cubit { brightness: 80, lightingMode: 1, timer: null, - type: '', + type: DeviceType.Lights, image: '', recentColors: [ 0xFF83D9FF, @@ -172,7 +172,7 @@ class DevicesCubit extends Cubit { brightness: 100, lightingMode: 1, timer: null, - type: '', + type: DeviceType.Lights, image: '', recentColors: [ 0xFF83D9FF, @@ -201,7 +201,7 @@ class DevicesCubit extends Cubit { id: "1", name: "Living Room Curtain", status: false, - type: '', + type: DeviceType.Curtain, image: '', timer: null, ), @@ -210,7 +210,7 @@ class DevicesCubit extends Cubit { id: "2", name: "Master Bedroom Curtain", status: false, - type: '', + type: DeviceType.Curtain, image: '', timer: null, ), diff --git a/lib/features/devices/model/device_category_model.dart b/lib/features/devices/model/device_category_model.dart index 756e4ca..c9f3303 100644 --- a/lib/features/devices/model/device_category_model.dart +++ b/lib/features/devices/model/device_category_model.dart @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; +import 'package:syncrow_app/utils/resource_manager/constants.dart'; class DevicesCategoryModel { final String name; @@ -35,12 +36,3 @@ class DevicesCategoryModel { } } } - -enum DeviceType { - AC, - Lights, - Door, - Curtain, - Screens, - Gateway, -} diff --git a/lib/features/devices/model/device_model.dart b/lib/features/devices/model/device_model.dart index 280ba6d..2c327f9 100644 --- a/lib/features/devices/model/device_model.dart +++ b/lib/features/devices/model/device_model.dart @@ -1,10 +1,15 @@ +import 'package:syncrow_app/generated/assets.dart'; +import 'package:syncrow_app/utils/resource_manager/constants.dart'; + abstract class DeviceModel { final String? id; final String? name; - final String? type; + final DeviceType? type; bool? status; final String? image; final double? timer; + + late final String icon; bool isSelected = false; DeviceModel({ @@ -14,5 +19,25 @@ abstract class DeviceModel { required this.status, required this.image, required this.timer, - }); + }) { + switch (type) { + case DeviceType.AC: + icon = Assets.iconsAC; + break; + case DeviceType.Lights: + icon = Assets.iconsLight; + break; + case DeviceType.Door: + icon = Assets.iconsDoorLock; + break; + case DeviceType.Curtain: + icon = Assets.iconsCurtain; + break; + case DeviceType.Gateway: + icon = Assets.iconsGateway; + break; + default: + icon = ''; + } + } } diff --git a/lib/features/devices/view/widgets/ACs/ac_interface.dart b/lib/features/devices/view/widgets/ACs/ac_interface.dart index 4f92f77..aceaf69 100644 --- a/lib/features/devices/view/widgets/ACs/ac_interface.dart +++ b/lib/features/devices/view/widgets/ACs/ac_interface.dart @@ -1,9 +1,13 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; +import 'package:flutter/services.dart'; import 'package:syncrow_app/features/devices/model/ac_model.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface_controls.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart'; +import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart'; +import 'package:syncrow_app/generated/assets.dart'; +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'; class AcInterface extends StatelessWidget { const AcInterface({super.key, required this.acModel}); @@ -12,30 +16,72 @@ class AcInterface extends StatelessWidget { @override Widget build(BuildContext context) { - return SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - ConstrainedBox( - constraints: const BoxConstraints( - maxHeight: 380, - ), - child: AcInterfaceTempUnit( - acModel: acModel, + return AnnotatedRegion( + value: SystemUiOverlayStyle( + statusBarColor: ColorsManager.primaryColor.withOpacity(0.5), + statusBarIconBrightness: Brightness.light, + ), + child: SafeArea( + child: Scaffold( + backgroundColor: ColorsManager.backgroundColor, + extendBodyBehindAppBar: true, + extendBody: true, + appBar: AppBar( + backgroundColor: Colors.transparent, + centerTitle: true, + title: BodyLarge( + text: acModel.name ?? "", + fontColor: ColorsManager.primaryColor, + fontWeight: FontsManager.bold, ), ), - const SizedBox( - height: 10, - ), - ConstrainedBox( - constraints: const BoxConstraints( - maxHeight: 120, + body: Container( + width: MediaQuery.sizeOf(context).width, + height: MediaQuery.sizeOf(context).height, + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage( + Assets.imagesBackground, + ), + fit: BoxFit.cover, + opacity: 0.4, + ), ), - child: AcInterfaceControls( - acModel: acModel, + child: Padding( + padding: EdgeInsets.only( + top: Constants.appBarHeight, + left: Constants.defaultPadding, + right: Constants.defaultPadding, + ), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + ConstrainedBox( + constraints: const BoxConstraints( + maxHeight: 380, + ), + child: AcInterfaceTempUnit( + acModel: acModel, + ), + ), + const SizedBox( + height: 10, + ), + ConstrainedBox( + constraints: const BoxConstraints( + maxHeight: 120, + ), + child: AcInterfaceControls( + acModel: acModel, + ), + ), + ], + ), + ), ), ), - ], + ), ), ); } diff --git a/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart b/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart index 57d4110..9882d00 100644 --- a/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart +++ b/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart @@ -23,124 +23,127 @@ class AcInterfaceTempUnit extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return DefaultContainer( - child: Column( - children: [ - Expanded( - flex: 8, - child: SizedBox( - width: 300, - child: SleekCircularSlider( - appearance: CircularSliderAppearance( - customWidths: CustomSliderWidths( - progressBarWidth: 15, - trackWidth: 15, - shadowWidth: 0, - ), - customColors: CustomSliderColors( - progressBarColor: - ColorsManager.primaryColor.withOpacity(.6), - trackColor: ColorsManager.greyColor, - dotColor: Colors.transparent, - ), - infoProperties: InfoProperties( - //TODO: move to strings manager - bottomLabelText: 'CURRENT TEMP', - bottomLabelStyle: context.bodyLarge.copyWith( - color: Colors.grey, - fontWeight: FontsManager.regular, + return BlocProvider( + create: (context) => AcCubit(), + child: BlocBuilder( + builder: (context, state) { + return DefaultContainer( + child: Column( + children: [ + Expanded( + flex: 8, + child: SizedBox( + width: 300, + child: SleekCircularSlider( + appearance: CircularSliderAppearance( + customWidths: CustomSliderWidths( + progressBarWidth: 15, + trackWidth: 15, + shadowWidth: 0, ), - modifier: (double value) { - return '${acModel.temperature.toStringAsFixed(1)}°C'; - }, - mainLabelStyle: context.titleLarge.copyWith( - height: 0, - letterSpacing: -3, - color: Colors.black, - fontSize: 60, - shadows: [ - Shadow( - color: Colors.black.withOpacity(0.5), - offset: const Offset(0, 3), - blurRadius: 6, - ), - ], + customColors: CustomSliderColors( + progressBarColor: + ColorsManager.primaryColor.withOpacity(.6), + trackColor: ColorsManager.greyColor, + dotColor: Colors.transparent, + ), + infoProperties: InfoProperties( + //TODO: move to strings manager + bottomLabelText: 'CURRENT TEMP', + bottomLabelStyle: context.bodyLarge.copyWith( + color: Colors.grey, + fontWeight: FontsManager.regular, + ), + modifier: (double value) { + return '${acModel.temperature.toStringAsFixed(1)}°C'; + }, + mainLabelStyle: context.titleLarge.copyWith( + height: 0, + letterSpacing: -3, + color: Colors.black, + fontSize: 60, + shadows: [ + Shadow( + color: Colors.black.withOpacity(0.5), + offset: const Offset(0, 3), + blurRadius: 6, + ), + ], + ), ), ), + min: acModel.bounds.min, + max: acModel.bounds.max, + initialValue: acModel.temperature, + onChange: (value) { + String valueAsString = value.toStringAsFixed(1); + if (valueAsString.endsWith(".0") || + valueAsString.endsWith(".5")) { + value = double.parse(valueAsString); + AcCubit.get(context).setACTemp(acModel, value); + } + }, ), - min: acModel.bounds.min, - max: acModel.bounds.max, - initialValue: acModel.temperature, - onChange: (value) { - String valueAsString = value.toStringAsFixed(1); - if (valueAsString.endsWith(".0") || - valueAsString.endsWith(".5")) { - value = double.parse(valueAsString); - AcCubit.get(context).setTempToAll(value); - } - }, ), ), - ), - Expanded( - flex: 2, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - SizedBox.square( - dimension: 24, - child: InkWell( - onTap: () { - AcCubit.get(context) - .setACTemp(acModel, acModel.coolTo); - acModel.coolTo -= .5; - }, - child: SvgPicture.asset( - Assets.iconsMinus, + Expanded( + flex: 2, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + SizedBox.square( + dimension: 24, + child: InkWell( + onTap: () { + AcCubit.get(context) + .setACTemp(acModel, acModel.coolTo); + acModel.coolTo -= .5; + }, + child: SvgPicture.asset( + Assets.iconsMinus, + ), ), ), - ), - Column( - children: [ - BodyLarge( - text: "${acModel.coolTo}° C", - style: context.bodyLarge.copyWith( - color: - ColorsManager.primaryColor.withOpacity(0.6), - fontWeight: FontsManager.bold, - fontSize: 30, - height: 0), - ), - const BodyMedium( - text: 'COOL TO', - fontSize: 18, - ) - ], - ), - SizedBox.square( - dimension: 24, - child: InkWell( - onTap: () { - AcCubit.get(context) - .setACTemp(acModel, acModel.coolTo); - acModel.coolTo += .5; - }, - child: SvgPicture.asset( - Assets.iconsPlus, - height: 24, - width: 24, + Column( + children: [ + BodyLarge( + text: "${acModel.coolTo}° C", + style: context.bodyLarge.copyWith( + color: + ColorsManager.primaryColor.withOpacity(0.6), + fontWeight: FontsManager.bold, + fontSize: 30, + height: 0), + ), + const BodyMedium( + text: 'COOL TO', + fontSize: 18, + ) + ], + ), + SizedBox.square( + dimension: 24, + child: InkWell( + onTap: () { + AcCubit.get(context) + .setACTemp(acModel, acModel.coolTo); + acModel.coolTo += .5; + }, + child: SvgPicture.asset( + Assets.iconsPlus, + height: 24, + width: 24, + ), ), ), - ), - ], - ), - ) - ], - ), - ); - }, + ], + ), + ) + ], + ), + ); + }, + ), ); } } diff --git a/lib/features/devices/view/widgets/room_page.dart b/lib/features/devices/view/widgets/room_page.dart index d9b673a..4c0455a 100644 --- a/lib/features/devices/view/widgets/room_page.dart +++ b/lib/features/devices/view/widgets/room_page.dart @@ -1,12 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_svg/flutter_svg.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/shared_widgets/custom_switch.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/utils/context_extension.dart'; +import 'package:syncrow_app/features/devices/view/widgets/room_page_switch.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; class RoomPage extends StatelessWidget { @@ -16,6 +13,10 @@ class RoomPage extends StatelessWidget { @override Widget build(BuildContext context) { + List devices = []; + for (var category in room.categories) { + devices.addAll(category.devices); + } return Padding( padding: const EdgeInsets.symmetric(horizontal: Constants.defaultPadding), child: SingleChildScrollView( @@ -31,63 +32,9 @@ class RoomPage extends StatelessWidget { padding: const EdgeInsets.only(top: 10), physics: const NeverScrollableScrollPhysics(), shrinkWrap: true, - itemCount: room.categories.length, + itemCount: devices.length, itemBuilder: (_, index) { - return InkWell( - onTap: () { - DevicesCubit.get(context).selectCategory(index); - //Navigate to the chosen category view without animation - - // Navigator.push( - // context, - // CustomPageRoute( - // builder: (context) { - // return DevicesCubit.get(context) - // .chosenCategoryView!; - // }, - // ), - // ); - }, - child: DefaultContainer( - child: Padding( - padding: - const EdgeInsets.only(top: 10, right: 10, left: 10), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - SvgPicture.asset( - room.categories[index].icon, - fit: BoxFit.contain, - ), - CustomSwitch( - category: room.categories[index], - ), - ], - ), - Expanded( - child: FittedBox( - fit: BoxFit.scaleDown, - child: BodyLarge( - text: room.categories[index].name, - style: context.bodyLarge.copyWith( - fontWeight: FontWeight.bold, - height: 0, - fontSize: 24, - color: Colors.grey, - ), - ), - ), - ), - ], - ), - ), - ), - ); + return RoomPageSwitch(device: devices[index]); }, ); }, diff --git a/lib/features/devices/view/widgets/room_page_switch.dart b/lib/features/devices/view/widgets/room_page_switch.dart new file mode 100644 index 0000000..cfaafbe --- /dev/null +++ b/lib/features/devices/view/widgets/room_page_switch.dart @@ -0,0 +1,86 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/flutter_svg.dart'; +import 'package:syncrow_app/features/devices/model/ac_model.dart'; +import 'package:syncrow_app/features/devices/model/device_model.dart'; +import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface.dart'; +import 'package:syncrow_app/features/shared_widgets/custom_switch.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/utils/context_extension.dart'; +import 'package:syncrow_app/utils/helpers/custom_page_route.dart'; +import 'package:syncrow_app/utils/resource_manager/constants.dart'; + +class RoomPageSwitch extends StatelessWidget { + const RoomPageSwitch({ + super.key, + required this.device, + }); + + final DeviceModel device; + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: () { + //Navigate to the chosen category view without animation + + // Navigator.push( + // context, + // CustomPageRoute( + // builder: (context) { + // return DevicesCubit.get(context) + // .chosenCategoryView!; + // }, + // ), + // ); + + if (device.type == DeviceType.AC) { + Navigator.push( + context, + CustomPageRoute( + builder: (context) => AcInterface(acModel: device as ACModel), + ), + ); + } + }, + child: DefaultContainer( + child: Padding( + padding: const EdgeInsets.only(top: 10, right: 10, left: 10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SvgPicture.asset( + device.icon, + fit: BoxFit.contain, + ), + CustomSwitch( + device: device, + ), + ], + ), + Expanded( + child: FittedBox( + fit: BoxFit.scaleDown, + child: BodyLarge( + text: device.name ?? "", + style: context.bodyLarge.copyWith( + fontWeight: FontWeight.bold, + height: 0, + fontSize: 24, + color: Colors.grey, + ), + ), + ), + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/features/shared_widgets/custom_switch.dart b/lib/features/shared_widgets/custom_switch.dart index c84e445..9e6c180 100644 --- a/lib/features/shared_widgets/custom_switch.dart +++ b/lib/features/shared_widgets/custom_switch.dart @@ -2,28 +2,42 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/model/device_category_model.dart'; +import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; class CustomSwitch extends StatelessWidget { - const CustomSwitch({super.key, required this.category}); + const CustomSwitch({super.key, this.category, this.device}) + : assert(category != null || device != null); - final DevicesCategoryModel category; + final DevicesCategoryModel? category; + + final DeviceModel? device; @override Widget build(BuildContext context) { return BlocBuilder( builder: (context, state) { + bool? status; + if (device != null) { + status = device!.status; + } else if (category != null) { + status = category!.devicesStatus; + } return GestureDetector( onTap: () { - DevicesCubit.get(context).changeCategorySwitchValue(category); + if (device != null) { + DevicesCubit.get(context).turnOnOffDevice(device!); + } else if (category != null) { + DevicesCubit.get(context).changeCategorySwitchValue(category!); + } }, child: Container( width: 45.0, height: 28.0, decoration: BoxDecoration( borderRadius: BorderRadius.circular(24.0), - color: category.devicesStatus != null - ? category.devicesStatus! + color: status != null + ? status ? ColorsManager.primaryColor : const Color(0xFFD9D9D9) : const Color(0xFFD9D9D9), @@ -39,8 +53,8 @@ class CustomSwitch extends StatelessWidget { child: Padding( padding: const EdgeInsets.all(2.0), child: Container( - alignment: category.devicesStatus != null - ? category.devicesStatus! + alignment: status != null + ? status ? Alignment.centerRight : Alignment.centerLeft : Alignment.centerLeft, @@ -49,8 +63,8 @@ class CustomSwitch extends StatelessWidget { height: 20.0, decoration: BoxDecoration( shape: BoxShape.circle, - color: category.devicesStatus != null - ? category.devicesStatus! + color: status != null + ? status ? ColorsManager.primaryColor : Colors.grey : Colors.grey, diff --git a/lib/generated/assets.dart b/lib/generated/assets.dart index 4f80ef8..b2c1033 100644 --- a/lib/generated/assets.dart +++ b/lib/generated/assets.dart @@ -51,7 +51,9 @@ class Assets { static const String imagesAutomation = 'assets/images/automation.jpg'; static const String imagesBackground = 'assets/images/Background.png'; static const String imagesBlackLogo = 'assets/images/black-logo.png'; + static const String imagesBlind = 'assets/images/blind.png'; static const String imagesBoxEmpty = 'assets/images/box-empty.jpg'; + static const String imagesCurtain = 'assets/images/curtain.png'; static const String imagesLogoHorizontal = 'assets/images/logo_horizontal.png'; static const String imagesTestDash = 'assets/images/test_dash.png'; diff --git a/lib/services/api/http_service.dart b/lib/services/api/http_service.dart index e9941a7..337c7b2 100644 --- a/lib/services/api/http_service.dart +++ b/lib/services/api/http_service.dart @@ -21,17 +21,7 @@ class HTTPService { receiveTimeout: const Duration(milliseconds: 60000), ), ); - // (client.httpClientAdapter as IOHttpClientAdapter).createHttpClient = () { - // client. = (X509Certificate cert, String host, int port) { - // // TODO add SSL certificate - // // if(cert.pem == certificateString){ // Verify the certificate - // // return true; - // // } - // // return false; - // return true; - // }; - // return client; - // }; + client.interceptors.add(locator()); return client; } diff --git a/lib/utils/resource_manager/constants.dart b/lib/utils/resource_manager/constants.dart index b0baee1..f836efb 100644 --- a/lib/utils/resource_manager/constants.dart +++ b/lib/utils/resource_manager/constants.dart @@ -10,3 +10,12 @@ abstract class Constants { static const double defaultPadding = 16; } + +enum DeviceType { + AC, + Lights, + Door, + Curtain, + Screens, + Gateway, +}