Files
syncrow-app/lib/features/devices/view/widgets/universal_switch.dart
Mohammad Salameh bff4b9493c Refactor device control logic and add temperature and fan speed enums
- Refactor device control logic in the app to improve readability and maintainability.
- Add temperature modes (hot, cold, wind) and fan speeds (auto, low, middle, high) enums.
- Update icon mappings and utility functions for temperature modes and fan speeds.
2024-04-03 18:54:21 +03:00

95 lines
3.2 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/utils/resource_manager/strings_manager.dart';
import '../../../../utils/resource_manager/color_manager.dart';
import '../../../shared_widgets/text_widgets/body_medium.dart';
class UniversalSwitch extends StatelessWidget {
const UniversalSwitch({
super.key,
required this.category,
});
final DevicesCategoryModel category;
@override
Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) {
bool? status = category.devicesStatus;
return Row(
children: <Widget>[
Expanded(
child: InkWell(
onTap: () {
DevicesCubit.getInstance().turnAllDevicesOn(category);
},
child: Container(
height: 60,
decoration: BoxDecoration(
color: status != null
? status
? ColorsManager.primaryColor
: Colors.white
: Colors.white,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(15),
bottomLeft: Radius.circular(15),
),
),
child: Center(
child: BodyMedium(
text: StringsManager.on,
fontColor: status != null
? status
? Colors.white
: null
: null,
fontWeight: FontWeight.bold,
),
),
),
),
),
Expanded(
child: InkWell(
onTap: () {
DevicesCubit.getInstance().turnAllDevicesOff(category);
},
child: Container(
height: 60,
decoration: BoxDecoration(
color: status != null
? status
? Colors.white
: ColorsManager.primaryColor
: Colors.white,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(15),
bottomRight: Radius.circular(15),
),
),
child: Center(
child: BodyMedium(
text: StringsManager.off,
fontColor: status != null
? status
? null
: Colors.white
: null,
fontWeight: FontWeight.bold,
),
),
),
),
),
],
);
},
);
}
}