Moved wall sensor files

This commit is contained in:
Mohammad Salameh
2024-04-22 10:13:40 +03:00
parent 2eeee63e1d
commit 072a043aaa
4 changed files with 327 additions and 349 deletions

View File

@ -1,349 +0,0 @@
part of "wall_sensor_interface.dart";
class ParametersList extends StatelessWidget {
const ParametersList({
super.key,
required this.wallSensor,
});
final DeviceModel wallSensor;
@override
Widget build(BuildContext context) {
return Expanded(
flex: 7,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: List.generate(
wallSensorButtons.length,
(index) {
if (index == 3) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
DefaultContainer(
padding: const EdgeInsets.symmetric(
vertical: 12, horizontal: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
InkWell(
onTap: () {
showParameterDialog(
context,
'Motion Detection Sensitivity',
wallSensor,
5,
0,
10,
);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
children: [
const BodySmall(
text: 'Motion\nDetectionn\nSensitivity',
textAlign: TextAlign.center),
BodyLarge(
text: '5',
style: context.bodyLarge
.copyWith(fontWeight: FontsManager.bold),
),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Container(
width: 1,
height: 45,
color: ColorsManager.greyColor,
),
),
Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const BodySmall(
text: 'Motionless\nDetection\nSensitivity',
textAlign: TextAlign.center),
BodyLarge(
text: '5',
style: context.bodyLarge.copyWith(
fontWeight: FontsManager.bold,
),
),
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Container(
width: 1,
height: 45,
color: ColorsManager.greyColor,
),
),
Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const BodySmall(
text: 'Far\nDetection',
textAlign: TextAlign.center),
BodyLarge(
text: '600cm',
style: context.bodyLarge.copyWith(
fontWeight: FontsManager.bold,
),
),
],
),
],
),
),
listItem(wallSensorButtons[index], context, wallSensor)
],
);
}
return listItem(wallSensorButtons[index], context, wallSensor);
},
),
),
),
);
}
final List<Map<String, Object?>> wallSensorButtons = const [
{
'icon': Assets.presenceSensorAssetsTime,
'title': 'Presence Time',
'value': 0,
'unit': 'min',
'page': null,
},
{
'icon': Assets.presenceSensorAssetsDistance,
'title': 'Current Distance',
'value': 279,
'unit': 'cm',
'dialog': null,
},
{
'icon': Assets.presenceSensorAssetsIlluminanceValue,
'title': 'Illuminance Value',
'value': 0,
'unit': 'Lux',
'page': null,
},
{
'icon': Assets.presenceSensorAssetsEmpty,
'title': 'Nobody Time',
'value': 10,
'unit': 'sec',
'dialog': null,
},
{
'icon': Assets.presenceSensorAssetsIndicator,
'title': 'Indicator',
'page': null,
},
{
'icon': Assets.presenceSensorAssetsRecord,
'title': 'Presence Record',
'page': null,
},
{
'icon': Assets.presenceSensorAssetsIlluminanceRecord,
'title': 'Illuminance Record',
'page': null,
},
];
}
Widget listItem(
Map<String, Object?> wallSensorButton,
BuildContext context,
DeviceModel wallSensor,
) {
return DefaultContainer(
margin: const EdgeInsets.only(bottom: 5),
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 20),
onTap: () {
if (wallSensorButton['page'] != null) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => wallSensorButton['page'] as Widget,
),
);
}
},
child: Row(
children: [
SvgPicture.asset(
wallSensorButton['icon'] as String,
),
const SizedBox(
width: 25,
),
BodyMedium(text: wallSensorButton['title'] as String),
if (wallSensorButton['value'] != null) const Spacer(),
if (wallSensorButton['value'] != null)
BodyMedium(
text: '${wallSensorButton['value']}${wallSensorButton['unit']}',
style: context.bodyMedium.copyWith(color: ColorsManager.greyColor),
),
if (wallSensorButton['value'] != null)
if (wallSensorButton['title'] == 'Indicator')
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Transform.scale(
scale: .8,
child: CupertinoSwitch(
value: false,
onChanged: (value) {},
applyTheme: true,
)),
],
),
),
// CustomSwitch(device: wallSensor),
if (wallSensorButton['title'] == 'Nobody Time')
const Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(
Icons.arrow_forward_ios,
color: ColorsManager.greyColor,
size: 15,
),
],
),
],
),
);
}
showParameterDialog(
BuildContext context,
String title,
DeviceModel wallSensor,
int value,
int min,
int max,
) {
showDialog(
context: context,
builder: (context) => Dialog(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
padding: const EdgeInsets.only(top: 20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
BodyMedium(
text: title,
style: context.bodyMedium.copyWith(
color: ColorsManager.primaryColorWithOpacity,
fontWeight: FontsManager.extraBold,
),
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 15,
horizontal: 50,
),
child: Container(
height: 1,
width: double.infinity,
color: ColorsManager.greyColor,
),
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10,
),
child: TitleMedium(
text: value.toString(),
style: context.titleMedium.copyWith(
color: Colors.black,
fontWeight: FontsManager.bold,
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Icon(Icons.minus),
IconButton(
onPressed: () {
value--;
},
icon: const Icon(
Icons.remove,
color: Colors.grey,
),
),
Slider(
value: value.toDouble(),
onChanged: (value) {
// value = value;
},
min: 0,
max: 10,
label: value.toString(),
inactiveColor: ColorsManager.greyColor,
),
IconButton(
onPressed: () {
value++;
},
icon: const Icon(
Icons.add,
color: Colors.grey,
),
),
],
),
Container(
height: 1,
width: double.infinity,
color: ColorsManager.greyColor,
),
Row(
children: [
Expanded(
child: Center(
child: BodyMedium(
text: 'Cancel',
style: context.bodyMedium
.copyWith(color: ColorsManager.greyColor),
),
)),
Container(
height: 50,
width: 1,
color: ColorsManager.greyColor,
),
Expanded(
child: Center(
child: BodyMedium(
text: 'Confirm',
style: context.bodyMedium.copyWith(
color: ColorsManager.primaryColorWithOpacity),
),
)),
],
)
],
),
),
));
}

View File

@ -0,0 +1,324 @@
part of "wall_sensor_interface.dart";
class ParametersList extends StatelessWidget {
const ParametersList({
super.key,
required this.wallSensor,
});
final DeviceModel wallSensor;
@override
Widget build(BuildContext context) {
return Expanded(
flex: 7,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: List.generate(
wallSensorButtons.length,
(index) {
if (index == 3) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
DefaultContainer(
padding: const EdgeInsets.symmetric(
vertical: 12, horizontal: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
InkWell(
onTap: () {
if ((wallSensor.isOnline ?? false) == false) {
return;
}
String controlCode = 'motion_sensitivity_value';
showDialog(
context: context,
builder: (context) => ParameterControlDialog(
title: 'Motion Detection Sensitivity',
sensor: wallSensor,
controlCode: controlCode,
value: wallSensor.status
.firstWhere((element) =>
element.code == controlCode)
.value as int,
min: wallSensor.functions
.firstWhere((element) =>
element.code == controlCode)
.values
?.min ??
0,
max: wallSensor.functions
.firstWhere((element) =>
element.code == controlCode)
.values
?.max ??
0,
),
);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
children: [
const BodySmall(
text: 'Motion\nDetection\nSensitivity',
textAlign: TextAlign.center),
BodyLarge(
text: wallSensor.status
.firstWhere((element) =>
element.code ==
'motion_sensitivity_value')
.value
.toString(),
style: context.bodyLarge
.copyWith(fontWeight: FontsManager.bold),
),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Container(
width: 1,
height: 45,
color: ColorsManager.greyColor,
),
),
InkWell(
onTap: () {
if ((wallSensor.isOnline ?? false) == false) {
return;
}
String controlCode = 'motionless_sensitivity';
showDialog(
context: context,
builder: (context) => ParameterControlDialog(
title: 'Motionless Detection Sensitivity',
sensor: wallSensor,
controlCode: controlCode,
value: wallSensor.status
.firstWhere((element) =>
element.code == controlCode)
.value as int,
min: wallSensor.functions
.firstWhere((element) =>
element.code == controlCode)
.values
?.min ??
0,
max: wallSensor.functions
.firstWhere((element) =>
element.code == controlCode)
.values
?.max ??
0,
),
);
},
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const BodySmall(
text: 'Motionless\nDetection\nSensitivity',
textAlign: TextAlign.center),
BodyLarge(
text: wallSensor.status
.firstWhere((element) =>
element.code ==
'motionless_sensitivity')
.value
.toString(),
style: context.bodyLarge.copyWith(
fontWeight: FontsManager.bold,
),
),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Container(
width: 1,
height: 45,
color: ColorsManager.greyColor,
),
),
InkWell(
onTap: () {
if ((wallSensor.isOnline ?? false) == false) {
return;
}
String controlCode = 'far_detection';
showDialog(
context: context,
builder: (context) => ParameterControlDialog(
title: 'Far Detection',
sensor: wallSensor,
controlCode: controlCode,
value: wallSensor.status
.firstWhere((element) =>
element.code == controlCode)
.value as int,
min: wallSensor.functions
.firstWhere((element) =>
element.code == controlCode)
.values
?.min ??
0,
max: wallSensor.functions
.firstWhere((element) =>
element.code == controlCode)
.values
?.max ??
0,
),
);
},
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const BodySmall(
text: 'Far\nDetection',
textAlign: TextAlign.center),
BodyLarge(
text:
'${wallSensor.status.firstWhere((element) => element.code == 'far_detection').value.toString()}${wallSensor.functions.firstWhere((element) => element.code == 'far_detection').values?.unit ?? ''}',
style: context.bodyLarge.copyWith(
fontWeight: FontsManager.bold,
),
),
],
),
),
],
),
),
listItem(wallSensorButtons[index], context, wallSensor)
],
);
}
return listItem(wallSensorButtons[index], context, wallSensor);
},
),
),
),
);
}
final List<Map<String, Object?>> wallSensorButtons = const [
{
'icon': Assets.presenceSensorAssetsTime,
'title': 'Presence Time',
'value': 0,
'unit': 'min',
'page': null,
},
{
'icon': Assets.presenceSensorAssetsDistance,
'title': 'Current Distance',
'value': 279,
'unit': 'cm',
'dialog': null,
},
{
'icon': Assets.presenceSensorAssetsIlluminanceValue,
'title': 'Illuminance Value',
'value': 0,
'unit': 'Lux',
'page': null,
},
{
'icon': Assets.presenceSensorAssetsEmpty,
'title': 'Nobody Time',
'value': 10,
'unit': 'sec',
'dialog': null,
},
{
'icon': Assets.presenceSensorAssetsIndicator,
'title': 'Indicator',
'page': null,
},
{
'icon': Assets.presenceSensorAssetsRecord,
'title': 'Presence Record',
'page': null,
},
{
'icon': Assets.presenceSensorAssetsIlluminanceRecord,
'title': 'Illuminance Record',
'page': null,
},
];
}
Widget listItem(
Map<String, Object?> wallSensorButton,
BuildContext context,
DeviceModel wallSensor,
) {
return DefaultContainer(
margin: const EdgeInsets.only(bottom: 5),
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 20),
onTap: () {
if (wallSensorButton['page'] != null) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => wallSensorButton['page'] as Widget,
),
);
}
},
child: Row(
children: [
SvgPicture.asset(
wallSensorButton['icon'] as String,
),
const SizedBox(
width: 25,
),
BodyMedium(text: wallSensorButton['title'] as String),
if (wallSensorButton['value'] != null) const Spacer(),
if (wallSensorButton['value'] != null)
BodyMedium(
text: '${wallSensorButton['value']}${wallSensorButton['unit']}',
style: context.bodyMedium.copyWith(color: ColorsManager.greyColor),
),
if (wallSensorButton['value'] != null)
if (wallSensorButton['title'] == 'Indicator')
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Transform.scale(
scale: .8,
child: CupertinoSwitch(
value: false,
onChanged: (value) {},
applyTheme: true,
)),
],
),
),
// CustomSwitch(device: wallSensor),
if (wallSensorButton['title'] == 'Nobody Time')
const Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(
Icons.arrow_forward_ios,
color: ColorsManager.greyColor,
size: 15,
),
],
),
],
),
);
}

View File

@ -2,6 +2,8 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_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/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
@ -16,6 +18,7 @@ import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
part "parameters_list.dart";
part "presence_indicator.dart";
part "parameter_control_dialog.dart";
class WallMountedInterface extends StatelessWidget {
const WallMountedInterface({super.key, required this.wallSensor});