Add three gang widgets for controlling three different switches

- Added ThreeGangBody, ThreeGangSwitch, and ThreeGangSwitchesView widgets
  for controlling three different switches in the UI.
- Updated constants file with functions for ThreeGang device type.
This commit is contained in:
Mohammad Salameh
2024-04-01 09:56:55 +03:00
parent 9368575154
commit 3031d19836
4 changed files with 484 additions and 3 deletions

View File

@ -0,0 +1,260 @@
import 'package:flutter/material.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_switch.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class ThreeGangBody extends StatelessWidget {
const ThreeGangBody({
super.key,
required this.device,
});
final DeviceModel device;
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Expanded(child: SizedBox.shrink()),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
children: [
ThreeGangSwitch(
control: DeviceControlModel(
deviceId: 'bfe10693d4fd263206ocq9',
code: 'switch_1',
value: true,
),
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Bedside Light",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
Column(
children: [
ThreeGangSwitch(
control: DeviceControlModel(
deviceId: 'bfe10693d4fd263206ocq9',
code: 'switch_2',
value: true,
),
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Ceiling Light",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
Column(
children: [
ThreeGangSwitch(
control: DeviceControlModel(
deviceId: 'bfe10693d4fd263206ocq9',
code: 'switch_3',
value: true,
),
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Spotlight",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
],
),
Expanded(
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
),
child: InkWell(
onTap: () {},
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(100),
),
child: Center(
child: BodySmall(
text: "On",
style: context.bodyMedium.copyWith(
color:
ColorsManager.primaryColorWithOpacity,
fontWeight: FontWeight.bold),
),
),
),
],
),
),
),
const SizedBox(height: 10),
BodySmall(
text: "All On",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
),
),
],
),
const SizedBox(
width: 20,
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
),
child: InkWell(
onTap: () {},
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(100),
),
child: Center(
child: Icon(
Icons.access_time,
color: ColorsManager.primaryColorWithOpacity,
size: 25,
),
),
),
],
),
),
),
const SizedBox(height: 10),
BodySmall(
text: "Timer",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
),
),
],
),
const SizedBox(
width: 20,
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
),
child: InkWell(
onTap: () {},
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(100),
),
child: Center(
child: BodySmall(
text: "Off",
style: context.bodyMedium.copyWith(
color:
ColorsManager.primaryColorWithOpacity,
fontWeight: FontWeight.bold),
),
),
),
],
),
),
),
const SizedBox(height: 10),
BodySmall(
text: "All Off",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
),
),
],
),
],
),
),
),
],
);
}
}

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 ThreeGangSwitch extends StatelessWidget {
const ThreeGangSwitch({
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,
),
),
),
],
),
);
},
);
}
}

View File

@ -0,0 +1,61 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/function_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/ACs/category_view_app_bar.dart';
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_body.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';
class ThreeGangSwitchesView extends StatelessWidget {
const ThreeGangSwitchesView({super.key});
@override
Widget build(BuildContext context) {
return AnnotatedRegion(
value: SystemUiOverlayStyle(
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
statusBarIconBrightness: Brightness.light,
),
child: SafeArea(
child: Scaffold(
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: const CategoryViewAppBar(),
body: BlocBuilder<HomeCubit, HomeState>(
builder: (context, state) {
return Container(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
Assets.imagesBackground,
),
fit: BoxFit.cover,
opacity: 0.4,
),
),
child: Padding(
padding: EdgeInsets.only(
top: Constants.appBarHeight,
left: Constants.defaultPadding,
right: Constants.defaultPadding,
bottom: Constants.bottomNavBarHeight,
),
child: ThreeGangBody(
device: DeviceModel(),
),
),
);
},
)),
),
);
}
}

View File

@ -1,4 +1,6 @@
//ignore_for_file: constant_identifier_names //ignore_for_file: constant_identifier_names
import 'package:syncrow_app/features/devices/model/function_model.dart';
abstract class Constants { abstract class Constants {
static const String languageCode = "en"; static const String languageCode = "en";
@ -16,12 +18,99 @@ abstract class Constants {
enum DeviceType { enum DeviceType {
AC, AC,
Lights, LightBulb,
DoorLock, DoorLock,
Curtain, Curtain,
Blind,
ThreeGang, ThreeGang,
Gateway, Gateway,
Sensors, CeilingSensor,
Gang, WallSensor,
Other, Other,
} }
Map<String, DeviceType> devicesTypesMap = {
"AC": DeviceType.AC,
"LB": DeviceType.LightBulb,
"DL": DeviceType.DoorLock,
"WC": DeviceType.Curtain,
"WB": DeviceType.Blind,
"3G": DeviceType.ThreeGang,
"GW": DeviceType.Gateway,
"CPS": DeviceType.CeilingSensor,
"WPS": DeviceType.WallSensor,
"Other": DeviceType.Other,
};
Map<DeviceType, List<FunctionModel>> devicesFunctionsMap = {
DeviceType.AC: [
FunctionModel(code: 'switch', type: 'Boolean', values: '{}'),
FunctionModel(
code: 'mode', type: 'Enum', values: '{"range":["cold","hot","wind"]}'),
FunctionModel(
code: 'temp_set',
type: 'Integer',
values: '{"unit":"℃","min":200,"max":300,"scale":1,"step":5}'),
FunctionModel(
code: 'level',
type: 'Enum',
values: '{"range":["low","middle","high","auto"]}'),
FunctionModel(code: 'child_lock', type: 'Boolean', values: '{}'),
],
DeviceType.Gateway: [
FunctionModel(code: 'switch_alarm_sound', type: 'Boolean', values: '{}'),
FunctionModel(
code: 'master_state',
type: 'Enum',
values: '{"range":["normal","alarm"]}'),
FunctionModel(code: 'factory_reset', type: 'Boolean', values: '{}'),
FunctionModel(
code: 'alarm_active', type: 'String', values: '{"maxlen":255}'),
],
DeviceType.CeilingSensor: [
FunctionModel(
code: 'sensitivity',
type: 'Integer',
values: '{"unit":"","min":1,"max":10,"scale":0,"step":1}'),
],
DeviceType.DoorLock: [
FunctionModel(code: 'remote_no_pd_setkey', type: 'Raw', values: '{}'),
FunctionModel(code: 'remote_no_dp_key', type: 'Raw', values: '{}'),
FunctionModel(code: 'normal_open_switch', type: 'Boolean', values: '{}'),
],
DeviceType.WallSensor: [
FunctionModel(
code: 'far_detection',
type: 'Integer',
values: '{"unit":"cm","min":75,"max":600,"scale":0,"step":75}'),
FunctionModel(
code: 'presence_time',
type: 'Integer',
values: '{"unit":"Min","min":0,"max":65535,"scale":0,"step":1}'),
FunctionModel(
code: 'motion_sensitivity_value',
type: 'Integer',
values: '{"unit":"","min":1,"max":5,"scale":0,"step":1}'),
FunctionModel(
code: 'motionless_sensitivity',
type: 'Integer',
values: '{"unit":"","min":1,"max":5,"scale":0,"step":1}'),
FunctionModel(code: 'indicator', type: 'Boolean', values: '{}'),
],
DeviceType.ThreeGang: [
FunctionModel(code: 'switch_1', type: 'Boolean', values: '{}'),
FunctionModel(code: 'switch_2', type: 'Boolean', values: '{}'),
FunctionModel(code: 'switch_3', type: 'Boolean', values: '{}'),
FunctionModel(
code: 'countdown_1',
type: 'Integer',
values: '{"unit":"s","min":0,"max":43200,"scale":0,"step":1}'),
FunctionModel(
code: 'countdown_2',
type: 'Integer',
values: '{"unit":"s","min":0,"max":43200,"scale":0,"step":1}'),
FunctionModel(
code: 'countdown_3',
type: 'Integer',
values: '{"unit":"s","min":0,"max":43200,"scale":0,"step":1}'),
],
};