Add support for different device types in RoomPageSwitch

-Update the navigation approch to be device type orianted to the corresponding interface when tapped.
-Add three gang switch interface and related components
This commit is contained in:
Mohammad Salameh
2024-04-02 15:45:21 +03:00
parent 81625cd50e
commit ef41940333
5 changed files with 68 additions and 23 deletions

View File

@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class GangSwitch extends StatelessWidget {
const GangSwitch({
super.key,
required this.control,
});
final DeviceControlModel control;
@override
Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) {
return state is DeviceControlLoading
? const CircularProgressIndicator()
: InkWell(
overlayColor: MaterialStateProperty.all(Colors.transparent),
onTap: () {
DevicesCubit.get(context)
.deviceControl(control)
.then((value) {
print('Device control response: $value');
if (control.value ?? true) {
control.value = false;
} else {
control.value = true;
}
});
},
child: Stack(
alignment: !control.value!
? Alignment.topCenter
: Alignment.bottomCenter,
children: [
Container(
decoration: BoxDecoration(
borderRadius:
const BorderRadius.all(Radius.circular(100.0)),
color: !control.value!
? ColorsManager.primaryColorWithOpacity
: ColorsManager.switchOffColor,
),
width: 60,
height: 115,
),
Padding(
padding: const EdgeInsets.all(5.0),
child: SizedBox.square(
dimension: 60,
child: SvgPicture.asset(
!control.value!
? Assets.iconsLightSwitchOn
: Assets.iconsLightSwitchOff,
fit: BoxFit.fill,
),
),
),
],
),
);
},
);
}
}