Implemented room device interface

(AC only)
This commit is contained in:
Mohammad Salameh
2024-03-07 14:53:13 +03:00
parent bf275d5adf
commit f8e8591d13
12 changed files with 357 additions and 244 deletions

View File

@ -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/lights/lights_view.dart';
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_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/generated/assets.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
part 'spaces_state.dart'; part 'spaces_state.dart';
@ -36,7 +37,7 @@ class SpacesCubit extends Cubit<SpacesState> {
fanSpeed: 0, fanSpeed: 0,
tempMode: 0, tempMode: 0,
coolTo: 20, coolTo: 20,
type: '', type: DeviceType.AC,
image: '', image: '',
timer: null, timer: null,
bounds: Bounds( bounds: Bounds(
@ -60,7 +61,7 @@ class SpacesCubit extends Cubit<SpacesState> {
brightness: 20, brightness: 20,
lightingMode: 1, lightingMode: 1,
timer: null, timer: null,
type: '', type: DeviceType.Lights,
image: '', image: '',
recentColors: [ recentColors: [
0xFF83D9FF, 0xFF83D9FF,
@ -89,7 +90,7 @@ class SpacesCubit extends Cubit<SpacesState> {
id: "1", id: "1",
name: "Living Room Curtain", name: "Living Room Curtain",
status: false, status: false,
type: '', type: DeviceType.Curtain,
image: '', image: '',
timer: null, timer: null,
), ),
@ -118,7 +119,7 @@ class SpacesCubit extends Cubit<SpacesState> {
fanSpeed: 0, fanSpeed: 0,
tempMode: 0, tempMode: 0,
coolTo: 20, coolTo: 20,
type: '', type: DeviceType.AC,
image: '', image: '',
timer: null, timer: null,
bounds: Bounds( bounds: Bounds(
@ -142,7 +143,7 @@ class SpacesCubit extends Cubit<SpacesState> {
brightness: 20, brightness: 20,
lightingMode: 1, lightingMode: 1,
timer: null, timer: null,
type: '', type: DeviceType.Lights,
image: '', image: '',
recentColors: [ recentColors: [
0xFF83D9FF, 0xFF83D9FF,
@ -171,7 +172,7 @@ class SpacesCubit extends Cubit<SpacesState> {
id: "1", id: "1",
name: "Living Room Curtain", name: "Living Room Curtain",
status: false, status: false,
type: '', type: DeviceType.Curtain,
image: '', image: '',
timer: null, timer: null,
), ),
@ -229,7 +230,6 @@ class SpacesCubit extends Cubit<SpacesState> {
unselectRoom(); unselectRoom();
} else { } else {
selectedRoom = selectedSpace.rooms[index - 1]; selectedRoom = selectedSpace.rooms[index - 1];
print(selectedRoom!.name);
} }
emit(RoomSelected(selectedRoom!)); emit(RoomSelected(selectedRoom!));
} }
@ -245,7 +245,6 @@ class SpacesCubit extends Cubit<SpacesState> {
unselectRoom(); unselectRoom();
} else { } else {
selectedRoom = selectedSpace.rooms[index - 1]; selectedRoom = selectedSpace.rooms[index - 1];
print(selectedRoom!.name);
} }
emit(RoomSelected(selectedRoom!)); emit(RoomSelected(selectedRoom!));
} }

View File

@ -2,17 +2,17 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.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/ac_model.dart';
import 'package:syncrow_app/features/devices/model/curtain_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/device_model.dart';
import 'package:syncrow_app/features/devices/model/light_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/curtains/curtain_view.dart';
import 'package:syncrow_app/features/devices/view/widgets/gateway/gateway_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/screens/screens_view.dart';
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_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/generated/assets.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
import '../model/device_category_model.dart';
import '../view/widgets/ACs/acs_view.dart';
import '../view/widgets/lights/lights_view.dart';
part 'devices_state.dart'; part 'devices_state.dart';
@ -32,7 +32,7 @@ class DevicesCubit extends Cubit<DevicesState> {
fanSpeed: 0, fanSpeed: 0,
tempMode: 0, tempMode: 0,
coolTo: 20, coolTo: 20,
type: '', type: DeviceType.AC,
image: '', image: '',
timer: null, timer: null,
bounds: Bounds( bounds: Bounds(
@ -48,7 +48,7 @@ class DevicesCubit extends Cubit<DevicesState> {
fanSpeed: 0, fanSpeed: 0,
tempMode: 0, tempMode: 0,
coolTo: 20, coolTo: 20,
type: '', type: DeviceType.AC,
image: '', image: '',
timer: null, timer: null,
bounds: Bounds( bounds: Bounds(
@ -64,7 +64,7 @@ class DevicesCubit extends Cubit<DevicesState> {
fanSpeed: 0, fanSpeed: 0,
tempMode: 0, tempMode: 0,
coolTo: 20, coolTo: 20,
type: '', type: DeviceType.AC,
image: '', image: '',
timer: null, timer: null,
bounds: Bounds( bounds: Bounds(
@ -80,7 +80,7 @@ class DevicesCubit extends Cubit<DevicesState> {
fanSpeed: 0, fanSpeed: 0,
tempMode: 0, tempMode: 0,
coolTo: 20, coolTo: 20,
type: '', type: DeviceType.AC,
image: '', image: '',
timer: null, timer: null,
bounds: Bounds( bounds: Bounds(
@ -104,7 +104,7 @@ class DevicesCubit extends Cubit<DevicesState> {
brightness: 20, brightness: 20,
lightingMode: 1, lightingMode: 1,
timer: null, timer: null,
type: '', type: DeviceType.Lights,
image: '', image: '',
recentColors: [ recentColors: [
0xFF83D9FF, 0xFF83D9FF,
@ -121,7 +121,7 @@ class DevicesCubit extends Cubit<DevicesState> {
brightness: 40, brightness: 40,
lightingMode: 1, lightingMode: 1,
timer: null, timer: null,
type: '', type: DeviceType.Lights,
image: '', image: '',
recentColors: [ recentColors: [
0xFF83D9FF, 0xFF83D9FF,
@ -138,7 +138,7 @@ class DevicesCubit extends Cubit<DevicesState> {
brightness: 60, brightness: 60,
lightingMode: 1, lightingMode: 1,
timer: null, timer: null,
type: '', type: DeviceType.Lights,
image: '', image: '',
recentColors: [ recentColors: [
0xFF83D9FF, 0xFF83D9FF,
@ -155,7 +155,7 @@ class DevicesCubit extends Cubit<DevicesState> {
brightness: 80, brightness: 80,
lightingMode: 1, lightingMode: 1,
timer: null, timer: null,
type: '', type: DeviceType.Lights,
image: '', image: '',
recentColors: [ recentColors: [
0xFF83D9FF, 0xFF83D9FF,
@ -172,7 +172,7 @@ class DevicesCubit extends Cubit<DevicesState> {
brightness: 100, brightness: 100,
lightingMode: 1, lightingMode: 1,
timer: null, timer: null,
type: '', type: DeviceType.Lights,
image: '', image: '',
recentColors: [ recentColors: [
0xFF83D9FF, 0xFF83D9FF,
@ -201,7 +201,7 @@ class DevicesCubit extends Cubit<DevicesState> {
id: "1", id: "1",
name: "Living Room Curtain", name: "Living Room Curtain",
status: false, status: false,
type: '', type: DeviceType.Curtain,
image: '', image: '',
timer: null, timer: null,
), ),
@ -210,7 +210,7 @@ class DevicesCubit extends Cubit<DevicesState> {
id: "2", id: "2",
name: "Master Bedroom Curtain", name: "Master Bedroom Curtain",
status: false, status: false,
type: '', type: DeviceType.Curtain,
image: '', image: '',
timer: null, timer: null,
), ),

View File

@ -2,6 +2,7 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
class DevicesCategoryModel { class DevicesCategoryModel {
final String name; final String name;
@ -35,12 +36,3 @@ class DevicesCategoryModel {
} }
} }
} }
enum DeviceType {
AC,
Lights,
Door,
Curtain,
Screens,
Gateway,
}

View File

@ -1,10 +1,15 @@
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
abstract class DeviceModel { abstract class DeviceModel {
final String? id; final String? id;
final String? name; final String? name;
final String? type; final DeviceType? type;
bool? status; bool? status;
final String? image; final String? image;
final double? timer; final double? timer;
late final String icon;
bool isSelected = false; bool isSelected = false;
DeviceModel({ DeviceModel({
@ -14,5 +19,25 @@ abstract class DeviceModel {
required this.status, required this.status,
required this.image, required this.image,
required this.timer, 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 = '';
}
}
} }

View File

@ -1,9 +1,13 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.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/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_controls.dart';
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface_temp_unit.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 { class AcInterface extends StatelessWidget {
const AcInterface({super.key, required this.acModel}); const AcInterface({super.key, required this.acModel});
@ -12,30 +16,72 @@ class AcInterface extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SingleChildScrollView( return AnnotatedRegion(
child: Column( value: SystemUiOverlayStyle(
crossAxisAlignment: CrossAxisAlignment.stretch, statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
children: [ statusBarIconBrightness: Brightness.light,
ConstrainedBox( ),
constraints: const BoxConstraints( child: SafeArea(
maxHeight: 380, child: Scaffold(
), backgroundColor: ColorsManager.backgroundColor,
child: AcInterfaceTempUnit( extendBodyBehindAppBar: true,
acModel: acModel, extendBody: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: BodyLarge(
text: acModel.name ?? "",
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
), ),
), ),
const SizedBox( body: Container(
height: 10, width: MediaQuery.sizeOf(context).width,
), height: MediaQuery.sizeOf(context).height,
ConstrainedBox( decoration: const BoxDecoration(
constraints: const BoxConstraints( image: DecorationImage(
maxHeight: 120, image: AssetImage(
Assets.imagesBackground,
),
fit: BoxFit.cover,
opacity: 0.4,
),
), ),
child: AcInterfaceControls( child: Padding(
acModel: acModel, 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,
),
),
],
),
),
), ),
), ),
], ),
), ),
); );
} }

View File

@ -23,124 +23,127 @@ class AcInterfaceTempUnit extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<AcCubit, AcState>( return BlocProvider(
builder: (context, state) { create: (context) => AcCubit(),
return DefaultContainer( child: BlocBuilder<AcCubit, AcState>(
child: Column( builder: (context, state) {
children: [ return DefaultContainer(
Expanded( child: Column(
flex: 8, children: [
child: SizedBox( Expanded(
width: 300, flex: 8,
child: SleekCircularSlider( child: SizedBox(
appearance: CircularSliderAppearance( width: 300,
customWidths: CustomSliderWidths( child: SleekCircularSlider(
progressBarWidth: 15, appearance: CircularSliderAppearance(
trackWidth: 15, customWidths: CustomSliderWidths(
shadowWidth: 0, progressBarWidth: 15,
), trackWidth: 15,
customColors: CustomSliderColors( shadowWidth: 0,
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) { customColors: CustomSliderColors(
return '${acModel.temperature.toStringAsFixed(1)}°C'; progressBarColor:
}, ColorsManager.primaryColor.withOpacity(.6),
mainLabelStyle: context.titleLarge.copyWith( trackColor: ColorsManager.greyColor,
height: 0, dotColor: Colors.transparent,
letterSpacing: -3, ),
color: Colors.black, infoProperties: InfoProperties(
fontSize: 60, //TODO: move to strings manager
shadows: [ bottomLabelText: 'CURRENT TEMP',
Shadow( bottomLabelStyle: context.bodyLarge.copyWith(
color: Colors.black.withOpacity(0.5), color: Colors.grey,
offset: const Offset(0, 3), fontWeight: FontsManager.regular,
blurRadius: 6, ),
), 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(
Expanded( flex: 2,
flex: 2, child: Row(
child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[
children: <Widget>[ SizedBox.square(
SizedBox.square( dimension: 24,
dimension: 24, child: InkWell(
child: InkWell( onTap: () {
onTap: () { AcCubit.get(context)
AcCubit.get(context) .setACTemp(acModel, acModel.coolTo);
.setACTemp(acModel, acModel.coolTo); acModel.coolTo -= .5;
acModel.coolTo -= .5; },
}, child: SvgPicture.asset(
child: SvgPicture.asset( Assets.iconsMinus,
Assets.iconsMinus, ),
), ),
), ),
), Column(
Column( children: [
children: [ BodyLarge(
BodyLarge( text: "${acModel.coolTo}° C",
text: "${acModel.coolTo}° C", style: context.bodyLarge.copyWith(
style: context.bodyLarge.copyWith( color:
color: ColorsManager.primaryColor.withOpacity(0.6),
ColorsManager.primaryColor.withOpacity(0.6), fontWeight: FontsManager.bold,
fontWeight: FontsManager.bold, fontSize: 30,
fontSize: 30, height: 0),
height: 0), ),
), const BodyMedium(
const BodyMedium( text: 'COOL TO',
text: 'COOL TO', fontSize: 18,
fontSize: 18, )
) ],
], ),
), SizedBox.square(
SizedBox.square( dimension: 24,
dimension: 24, child: InkWell(
child: InkWell( onTap: () {
onTap: () { AcCubit.get(context)
AcCubit.get(context) .setACTemp(acModel, acModel.coolTo);
.setACTemp(acModel, acModel.coolTo); acModel.coolTo += .5;
acModel.coolTo += .5; },
}, child: SvgPicture.asset(
child: SvgPicture.asset( Assets.iconsPlus,
Assets.iconsPlus, height: 24,
height: 24, width: 24,
width: 24, ),
), ),
), ),
), ],
], ),
), )
) ],
], ),
), );
); },
}, ),
); );
} }
} }

View File

@ -1,12 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.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/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/room_model.dart';
import 'package:syncrow_app/features/shared_widgets/custom_switch.dart'; import 'package:syncrow_app/features/devices/view/widgets/room_page_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/resource_manager/constants.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart';
class RoomPage extends StatelessWidget { class RoomPage extends StatelessWidget {
@ -16,6 +13,10 @@ class RoomPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
List<DeviceModel> devices = [];
for (var category in room.categories) {
devices.addAll(category.devices);
}
return Padding( return Padding(
padding: const EdgeInsets.symmetric(horizontal: Constants.defaultPadding), padding: const EdgeInsets.symmetric(horizontal: Constants.defaultPadding),
child: SingleChildScrollView( child: SingleChildScrollView(
@ -31,63 +32,9 @@ class RoomPage extends StatelessWidget {
padding: const EdgeInsets.only(top: 10), padding: const EdgeInsets.only(top: 10),
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
itemCount: room.categories.length, itemCount: devices.length,
itemBuilder: (_, index) { itemBuilder: (_, index) {
return InkWell( return RoomPageSwitch(device: devices[index]);
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,
),
),
),
),
],
),
),
),
);
}, },
); );
}, },

View File

@ -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,
),
),
),
),
],
),
),
),
);
}
}

View File

@ -2,28 +2,42 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.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_category_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class CustomSwitch extends StatelessWidget { 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>( return BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) { builder: (context, state) {
bool? status;
if (device != null) {
status = device!.status;
} else if (category != null) {
status = category!.devicesStatus;
}
return GestureDetector( return GestureDetector(
onTap: () { 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( child: Container(
width: 45.0, width: 45.0,
height: 28.0, height: 28.0,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0), borderRadius: BorderRadius.circular(24.0),
color: category.devicesStatus != null color: status != null
? category.devicesStatus! ? status
? ColorsManager.primaryColor ? ColorsManager.primaryColor
: const Color(0xFFD9D9D9) : const Color(0xFFD9D9D9)
: const Color(0xFFD9D9D9), : const Color(0xFFD9D9D9),
@ -39,8 +53,8 @@ class CustomSwitch extends StatelessWidget {
child: Padding( child: Padding(
padding: const EdgeInsets.all(2.0), padding: const EdgeInsets.all(2.0),
child: Container( child: Container(
alignment: category.devicesStatus != null alignment: status != null
? category.devicesStatus! ? status
? Alignment.centerRight ? Alignment.centerRight
: Alignment.centerLeft : Alignment.centerLeft
: Alignment.centerLeft, : Alignment.centerLeft,
@ -49,8 +63,8 @@ class CustomSwitch extends StatelessWidget {
height: 20.0, height: 20.0,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
color: category.devicesStatus != null color: status != null
? category.devicesStatus! ? status
? ColorsManager.primaryColor ? ColorsManager.primaryColor
: Colors.grey : Colors.grey
: Colors.grey, : Colors.grey,

View File

@ -51,7 +51,9 @@ class Assets {
static const String imagesAutomation = 'assets/images/automation.jpg'; static const String imagesAutomation = 'assets/images/automation.jpg';
static const String imagesBackground = 'assets/images/Background.png'; static const String imagesBackground = 'assets/images/Background.png';
static const String imagesBlackLogo = 'assets/images/black-logo.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 imagesBoxEmpty = 'assets/images/box-empty.jpg';
static const String imagesCurtain = 'assets/images/curtain.png';
static const String imagesLogoHorizontal = static const String imagesLogoHorizontal =
'assets/images/logo_horizontal.png'; 'assets/images/logo_horizontal.png';
static const String imagesTestDash = 'assets/images/test_dash.png'; static const String imagesTestDash = 'assets/images/test_dash.png';

View File

@ -21,17 +21,7 @@ class HTTPService {
receiveTimeout: const Duration(milliseconds: 60000), 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<HTTPInterceptor>()); client.interceptors.add(locator<HTTPInterceptor>());
return client; return client;
} }

View File

@ -10,3 +10,12 @@ abstract class Constants {
static const double defaultPadding = 16; static const double defaultPadding = 16;
} }
enum DeviceType {
AC,
Lights,
Door,
Curtain,
Screens,
Gateway,
}