Files
syncrow-app/lib/features/shared_widgets/custom_switch.dart
Mohammad Salameh a20dfa3709 Refactor device status handling and update UI components
- Update device status handling from 'status' to 'isOnline' for consistency
- Remove unused imports and redundant code related to light switches
- Refactor UI components to use 'isOnline' instead of 'status' for device status
2024-04-01 09:58:51 +03:00

83 lines
2.8 KiB
Dart

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, this.category, this.device})
: assert(category != null || device != null);
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!.isOnline;
} else if (category != null) {
status = category!.devicesStatus;
}
return GestureDetector(
onTap: () {
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: status != null
? status
? ColorsManager.primaryColor
: const Color(0xFFD9D9D9)
: const Color(0xFFD9D9D9),
),
child: Center(
child: Container(
width: 40.0,
height: 23.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: Colors.white,
),
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Container(
alignment: status != null
? status
? Alignment.centerRight
: Alignment.centerLeft
: Alignment.centerLeft,
child: Container(
width: 20.0,
height: 20.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: status != null
? status
? ColorsManager.primaryColor
: Colors.grey
: Colors.grey,
),
),
),
),
),
),
),
);
},
);
}
}