mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00
Implemented room device interface
(AC only)
This commit is contained in:
@ -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<DevicesCubit, DevicesState>(
|
||||
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,
|
||||
|
Reference in New Issue
Block a user