mirror of
https://bitbucket.org/myhomie/myhomie_app.git
synced 2025-12-06 17:11:19 +00:00
505 lines
26 KiB
Dart
505 lines
26 KiB
Dart
import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mycore_api/api.dart';
|
|
|
|
import 'package:mycore_api/api.dart' as API;
|
|
import 'package:myhomie_app/Components/Alarms/getCurrentAlarmModeIcon.dart';
|
|
import 'package:myhomie_app/Components/Custom_Navigation_Bar/CustomAppBar.dart';
|
|
import 'package:myhomie_app/Components/check_input_container.dart';
|
|
import 'package:myhomie_app/Components/loading_common.dart';
|
|
import 'package:myhomie_app/Components/string_input_container.dart';
|
|
import 'package:myhomie_app/Models/homieContext.dart';
|
|
import 'package:myhomie_app/Screens/Main/Devices/deviceDetailPage.dart';
|
|
import 'package:myhomie_app/app_context.dart';
|
|
import 'package:myhomie_app/constants.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../Devices/devices.dart';
|
|
|
|
class RoomDetailPage extends StatefulWidget {
|
|
const RoomDetailPage({Key? key, required this.roomMainDetailDTO}) : super(key: key);
|
|
|
|
final API.RoomMainDetailDTO roomMainDetailDTO;
|
|
|
|
@override
|
|
State<RoomDetailPage> createState() => _RoomDetailPageState();
|
|
}
|
|
|
|
class _RoomDetailPageState extends State<RoomDetailPage> {
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
late API.RoomDetailDTO roomDetailDTO;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appContext = Provider.of<AppContext>(context);
|
|
Size size = MediaQuery.of(context).size;
|
|
//final notchInset = MediaQuery.of(context).padding;
|
|
|
|
HomieAppContext homieAppContext = appContext.getContext();
|
|
|
|
debugPrint(widget.roomMainDetailDTO.id!);
|
|
|
|
return Scaffold(
|
|
key: _scaffoldKey,
|
|
appBar: CustomAppBar(
|
|
title: widget.roomMainDetailDTO.name!,
|
|
//titleIcon: getAlarmModeIcon(widget.alarmMode),
|
|
isTextSizeButton: true,
|
|
),
|
|
body: FutureBuilder(
|
|
future: homieAppContext.clientAPI.roomApi!.roomGetDetail(widget.roomMainDetailDTO.id!),
|
|
builder: (context, AsyncSnapshot<API.RoomDetailDTO?> snapshot) {
|
|
if(snapshot.data != null ) {
|
|
roomDetailDTO = snapshot.data!;
|
|
|
|
return SingleChildScrollView(
|
|
child: RefreshIndicator(
|
|
color: Theme.of(context).primaryColor,
|
|
displacement: 20,
|
|
onRefresh: () async {
|
|
print("onRefresh");
|
|
//await homieAppContext.clientAPI.roomApi!.roomGetDetail(widget.roomMainDetailDTO.id!);
|
|
// for refresh
|
|
setState(() {});
|
|
},
|
|
child: Container(
|
|
height: size.height * 1,
|
|
child: GridView.builder(
|
|
shrinkWrap: true,
|
|
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1),
|
|
itemCount: roomDetailDTO.devices!.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return InkWell(
|
|
onLongPress: () {
|
|
debugPrint(roomDetailDTO.devices![index].toString());
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => DeviceDetailPage(
|
|
deviceDetailDTO: roomDetailDTO.devices![index]
|
|
)
|
|
),
|
|
);
|
|
/*setState(() {
|
|
//selectedSection = menuDTO.sections[index];
|
|
print("Hero to room detail");
|
|
});*/
|
|
},
|
|
onTap: () {
|
|
//if(roomDetailDTO.devices![index].meansOfCommunications!.contains(API.MeansOfCommunication.zigbee)) {
|
|
switch(roomDetailDTO.devices![index].type) {
|
|
case DeviceType.light:
|
|
case DeviceType.switch_:
|
|
debugPrint("Quick action supported !");
|
|
List<AutomationState>? statesToSend = [];
|
|
statesToSend.add(AutomationState(name: "state", value: "toggle"));
|
|
API.Action action = API.Action(
|
|
deviceId: roomDetailDTO.devices![index].id,
|
|
groupId: null,
|
|
type: ActionType.DEVICE,
|
|
providerId: roomDetailDTO.devices![index].providerId,
|
|
states: statesToSend,
|
|
isForce: true
|
|
);
|
|
|
|
print(action);
|
|
homieAppContext.clientAPI.deviceApi!.deviceSendAction(action);
|
|
break;
|
|
default:
|
|
debugPrint("Quick action not supported for this type of device");
|
|
break;
|
|
}
|
|
//}
|
|
},
|
|
child: Container(
|
|
decoration: boxDecorationDeviceDetail(roomDetailDTO.devices![index], false),
|
|
padding: const EdgeInsets.all(5),
|
|
margin: EdgeInsets.symmetric(vertical: 8, horizontal: 8),
|
|
child: Stack(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 35),
|
|
child: Align(
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
roomDetailDTO.devices![index].name!,
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].type != null)
|
|
Positioned(
|
|
top: 5,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
getDeviceIcon(roomDetailDTO.devices![index].type!),
|
|
size: 20,
|
|
//color: devices[index].status! ? kMainColor : kBackgroundSecondGrey,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isTemperature!)
|
|
Positioned(
|
|
bottom: 30,
|
|
left: 0,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.thermostat,
|
|
size: 20,
|
|
color: kMainColor,
|
|
),
|
|
Text(
|
|
roomDetailDTO.devices![index].temperature.toString(),
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isHumidity!)
|
|
Positioned(
|
|
bottom: 30,
|
|
left: roomDetailDTO.devices![index].isTemperature! ? 60 : 0,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.water,
|
|
size: 20,
|
|
color: kMainColor,
|
|
),
|
|
Text(
|
|
roomDetailDTO.devices![index].humidity!.toString(),
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isContact!)
|
|
Positioned(
|
|
bottom: 10,
|
|
right: 5,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.motion_photos_on_rounded,
|
|
size: 20,
|
|
color: !roomDetailDTO.devices![index].contact! ? kMainColor : kBackgroundSecondGrey,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isOccupation!)
|
|
Positioned(
|
|
bottom: 10,
|
|
right: roomDetailDTO.devices![index].isContact! ? 20 : 5,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.directions_walk,
|
|
size: 20,
|
|
color: roomDetailDTO.devices![index].occupation! ? kMainColor : kBackgroundSecondGrey,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isAirQuality!)
|
|
Positioned(
|
|
bottom: 5,
|
|
right: 20,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.air,
|
|
size: 20,
|
|
color: kBackgroundSecondGrey,
|
|
),
|
|
Text(
|
|
roomDetailDTO.devices![index].airQuality!.toString(),
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isConsumption!)
|
|
Positioned(
|
|
bottom: 5,
|
|
right: 0,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.money,
|
|
size: 20,
|
|
color: kBackgroundSecondGrey,
|
|
),
|
|
Text(
|
|
roomDetailDTO.devices![index].consumption!.roundToDouble().toString(),
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isCurrentPower!)
|
|
Positioned(
|
|
bottom: 5,
|
|
left: 0,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.power,
|
|
size: 20,
|
|
color: kBackgroundSecondGrey,
|
|
),
|
|
Text(
|
|
roomDetailDTO.devices![index].currentPower!.toStringAsFixed(2).toString(),
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isCO2!)
|
|
Positioned(
|
|
bottom: 5,
|
|
right: 5,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.co2,
|
|
size: 20,
|
|
color: kBackgroundSecondGrey,
|
|
),
|
|
Text(
|
|
roomDetailDTO.devices![index].cO2!.toString(),
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
if(roomDetailDTO.devices![index].isNoise!)
|
|
Positioned(
|
|
bottom: 5,
|
|
left: 0,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.volume_down,
|
|
size: 20,
|
|
color: kBackgroundSecondGrey,
|
|
),
|
|
Text(
|
|
roomDetailDTO.devices![index].noise!.toString(),
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isIlluminance!)
|
|
Positioned(
|
|
bottom: 5,
|
|
left: 0,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.light_mode_outlined,
|
|
size: 20,
|
|
color: kBackgroundSecondGrey,
|
|
),
|
|
Text(
|
|
roomDetailDTO.devices![index].illuminance!.toString(),
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isColorTemp!)
|
|
Positioned(
|
|
bottom: 5,
|
|
right: 5,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.color_lens,
|
|
size: 20,
|
|
color: kBackgroundSecondGrey,
|
|
),
|
|
Text(
|
|
roomDetailDTO.devices![index].colorTemp!.toString(),
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isColorXY!)
|
|
Positioned(
|
|
bottom: 5,
|
|
right: 5,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.colorize_outlined,
|
|
size: 20,
|
|
color: kBackgroundSecondGrey,
|
|
),
|
|
Text(
|
|
roomDetailDTO.devices![index].colorX!.toString() + ' ' + roomDetailDTO.devices![index].colorY!.toString() ,
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomDetailDTO.devices![index].isBrightness!)
|
|
Positioned(
|
|
bottom: 5,
|
|
left: 0,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.brightness_medium_rounded,
|
|
size: 20,
|
|
color: kBackgroundSecondGrey,
|
|
),
|
|
Text(
|
|
roomDetailDTO.devices![index].brightness!.toString(),
|
|
style: new TextStyle(fontSize: kDescriptionSmallDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
),
|
|
),
|
|
),
|
|
);
|
|
} else {
|
|
return const LoadingCommon();
|
|
}
|
|
}
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
boxDecorationDeviceDetail(DeviceDetailDTO deviceDetailDTO, bool isSelected) {
|
|
return BoxDecoration(
|
|
color: deviceDetailDTO.isState! ? deviceDetailDTO.state! ? kMainColor : kBackgroundLight : kBackgroundLight,
|
|
shape: BoxShape.rectangle,
|
|
borderRadius: BorderRadius.circular(20.0),
|
|
/*image: roomMainDetailDTO.imageSource != null ? new DecorationImage(
|
|
fit: BoxFit.contain,
|
|
colorFilter: !isSelected? new ColorFilter.mode(Colors.black.withOpacity(0.5), BlendMode.dstATop) : null,
|
|
image: new NetworkImage(
|
|
section.imageSource,
|
|
),
|
|
): null,*/
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: kBackgroundSecondGrey,
|
|
spreadRadius: 0.5,
|
|
blurRadius: 6,
|
|
offset: Offset(0, 1.5), // changes position of shadow
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
/*SizedBox(
|
|
width: size.width *1.1,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: StringInputContainer(
|
|
label: "Nom:",
|
|
color: kMainColor,
|
|
textColor: Colors.white,
|
|
initialValue: roomDetailDTO!.name,
|
|
onChanged: (String value) {
|
|
setState(() {
|
|
roomDetailDTO!.name = value;
|
|
// TODO SAVE or not
|
|
});
|
|
},
|
|
),
|
|
),
|
|
),*/
|
|
/*Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: CheckInputContainer(
|
|
icon: Icons.notifications_active,
|
|
label: "Notification :",
|
|
fontSize: 20,
|
|
isChecked: alarmModeDetailDTO!.notification!,
|
|
onChanged: (bool value) {
|
|
alarmModeDetailDTO!.notification = value;
|
|
},
|
|
),
|
|
),*/
|
|
/*ExpansionTile(
|
|
title: Text(
|
|
"Devices",
|
|
style: TextStyle(
|
|
fontSize: 18.0,
|
|
fontWeight: FontWeight.bold
|
|
),
|
|
),
|
|
children: [
|
|
for(var device in roomDetailDTO!.devices!)
|
|
ExpansionTile(
|
|
title: Text(device.name!),
|
|
children: <Widget>[
|
|
ListTile(
|
|
title: Text("type: "+ (device.type != null ? device.type!.value : 'no type') ),
|
|
),
|
|
ListTile(
|
|
title: Text("status: "+ device.status.toString()),
|
|
),
|
|
ListTile(
|
|
title: Text("last update date: "+ device.lastStateDate!.toLocal().toString()),
|
|
),
|
|
ListTile(
|
|
title: Text("lastState: "+ (device.lastState != null ? device.lastState! : 'no data')),
|
|
)
|
|
],
|
|
),
|
|
],
|
|
),*/ |