Add mode switch stateless widget
This commit is contained in:
@ -23,17 +23,18 @@ class Entity {
|
|||||||
"sensor"
|
"sensor"
|
||||||
];
|
];
|
||||||
|
|
||||||
double rightWidgetPadding = 14.0;
|
static const rightWidgetPadding = 14.0;
|
||||||
double leftWidgetPadding = 8.0;
|
static const leftWidgetPadding = 8.0;
|
||||||
double extendedWidgetHeight = 50.0;
|
static const extendedWidgetHeight = 50.0;
|
||||||
|
static const iconSize = 28.0;
|
||||||
|
static const stateFontSize = 16.0;
|
||||||
|
static const nameFontSize = 16.0;
|
||||||
|
static const smallFontSize = 14.0;
|
||||||
|
static const largeFontSize = 24.0;
|
||||||
|
static const inputWidth = 160.0;
|
||||||
|
static const rowPadding = 10.0;
|
||||||
|
|
||||||
double widgetHeight = 34.0;
|
double widgetHeight = 34.0;
|
||||||
double iconSize = 28.0;
|
|
||||||
double stateFontSize = 16.0;
|
|
||||||
double nameFontSize = 16.0;
|
|
||||||
double smallFontSize = 14.0;
|
|
||||||
double largeFontSize = 24.0;
|
|
||||||
double inputWidth = 160.0;
|
|
||||||
double rowPadding = 10.0;
|
|
||||||
|
|
||||||
Map attributes;
|
Map attributes;
|
||||||
String domain;
|
String domain;
|
||||||
@ -89,7 +90,10 @@ class Entity {
|
|||||||
Widget buildDefaultWidget(BuildContext context) {
|
Widget buildDefaultWidget(BuildContext context) {
|
||||||
return EntityModel(
|
return EntityModel(
|
||||||
entity: this,
|
entity: this,
|
||||||
child: DefaultEntityContainer(state: _buildStatePart(context)),
|
child: DefaultEntityContainer(
|
||||||
|
state: _buildStatePart(context),
|
||||||
|
height: widgetHeight,
|
||||||
|
),
|
||||||
handleTap: true,
|
handleTap: true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -113,7 +117,7 @@ class Entity {
|
|||||||
return EntityModel(
|
return EntityModel(
|
||||||
entity: this,
|
entity: this,
|
||||||
child: EntityPageContainer(children: <Widget>[
|
child: EntityPageContainer(children: <Widget>[
|
||||||
DefaultEntityContainer(state: _buildStatePartForPage(context)),
|
DefaultEntityContainer(state: _buildStatePartForPage(context), height: widgetHeight),
|
||||||
LastUpdatedWidget(),
|
LastUpdatedWidget(),
|
||||||
Divider(),
|
Divider(),
|
||||||
_buildAdditionalControlsForPage(context),
|
_buildAdditionalControlsForPage(context),
|
||||||
|
@ -64,7 +64,7 @@ class _ButtonControlWidgetState extends State<ButtonControlWidget> {
|
|||||||
"EXECUTE",
|
"EXECUTE",
|
||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
style:
|
style:
|
||||||
new TextStyle(fontSize: entityModel.entity.stateFontSize, color: Colors.blue),
|
new TextStyle(fontSize: Entity.stateFontSize, color: Colors.blue),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -398,7 +398,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
_resetVars(entity);
|
_resetVars(entity);
|
||||||
}
|
}
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.fromLTRB(entity.leftWidgetPadding, entity.rowPadding, entity.rightWidgetPadding, 0.0),
|
padding: EdgeInsets.fromLTRB(Entity.leftWidgetPadding, Entity.rowPadding, Entity.rightWidgetPadding, 0.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
@ -418,21 +418,10 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
|
|
||||||
Widget _buildAwayModeControl(ClimateEntity entity) {
|
Widget _buildAwayModeControl(ClimateEntity entity) {
|
||||||
if (entity.supportAwayMode) {
|
if (entity.supportAwayMode) {
|
||||||
return Row(
|
return ModeSwitchWidget(
|
||||||
children: <Widget>[
|
caption: "Away mode",
|
||||||
Expanded(
|
onChange: (value) => _setAwayMode(entity, value),
|
||||||
child: Text(
|
|
||||||
"Away mode",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: entity.stateFontSize
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Switch(
|
|
||||||
onChanged: (value) => _setAwayMode(entity, value),
|
|
||||||
value: _tmpAwayMode,
|
value: _tmpAwayMode,
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Container(height: 0.0, width: 0.0,);
|
return Container(height: 0.0, width: 0.0,);
|
||||||
@ -441,21 +430,10 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
|
|
||||||
Widget _buildOnOffControl(ClimateEntity entity) {
|
Widget _buildOnOffControl(ClimateEntity entity) {
|
||||||
if (entity.supportOnOff) {
|
if (entity.supportOnOff) {
|
||||||
return Row(
|
return ModeSwitchWidget(
|
||||||
children: <Widget>[
|
onChange: (value) => _setOnOf(entity, value),
|
||||||
Expanded(
|
caption: "On / Off",
|
||||||
child: Text(
|
value: !_tmpIsOff
|
||||||
"On / Off",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: entity.stateFontSize
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Switch(
|
|
||||||
onChanged: (value) => _setOnOf(entity, value),
|
|
||||||
value: !_tmpIsOff,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Container(height: 0.0, width: 0.0,);
|
return Container(height: 0.0, width: 0.0,);
|
||||||
@ -464,21 +442,10 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
|
|
||||||
Widget _buildAuxHeatControl(ClimateEntity entity) {
|
Widget _buildAuxHeatControl(ClimateEntity entity) {
|
||||||
if (entity.supportAuxHeat ) {
|
if (entity.supportAuxHeat ) {
|
||||||
return Row(
|
return ModeSwitchWidget(
|
||||||
children: <Widget>[
|
caption: "Aux heat",
|
||||||
Expanded(
|
onChange: (value) => _setAuxHeat(entity, value),
|
||||||
child: Text(
|
value: _tmpAuxHeat
|
||||||
"Aux heat",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: entity.stateFontSize
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Switch(
|
|
||||||
onChanged: (value) => _setAuxHeat(entity, value),
|
|
||||||
value: _tmpAuxHeat,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Container(height: 0.0, width: 0.0,);
|
return Container(height: 0.0, width: 0.0,);
|
||||||
@ -487,29 +454,11 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
|
|
||||||
Widget _buildOperationControl(ClimateEntity entity) {
|
Widget _buildOperationControl(ClimateEntity entity) {
|
||||||
if (entity.supportOperationMode) {
|
if (entity.supportOperationMode) {
|
||||||
return Column(
|
return ModeSelectorWidget(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
onChange: (mode) => _setOperationMode(entity, mode),
|
||||||
children: <Widget>[
|
options: entity.operationList,
|
||||||
Text("Operation", style: TextStyle(
|
caption: "Operation",
|
||||||
fontSize: entity.stateFontSize
|
value: _tmpOperationMode,
|
||||||
)),
|
|
||||||
DropdownButton<String>(
|
|
||||||
value: "$_tmpOperationMode",
|
|
||||||
iconSize: 30.0,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: entity.largeFontSize,
|
|
||||||
color: Colors.black,
|
|
||||||
),
|
|
||||||
items: entity.operationList.map((String value) {
|
|
||||||
return new DropdownMenuItem<String>(
|
|
||||||
value: value,
|
|
||||||
child: new Text(value),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
onChanged: (mode) => _setOperationMode(entity, mode),
|
|
||||||
),
|
|
||||||
Container(height: entity.rowPadding,)
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Container(height: 0.0, width: 0.0);
|
return Container(height: 0.0, width: 0.0);
|
||||||
@ -518,29 +467,11 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
|
|
||||||
Widget _buildFanControl(ClimateEntity entity) {
|
Widget _buildFanControl(ClimateEntity entity) {
|
||||||
if (entity.supportFanMode) {
|
if (entity.supportFanMode) {
|
||||||
return Column(
|
return ModeSelectorWidget(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
options: entity.fanList,
|
||||||
children: <Widget>[
|
onChange: (mode) => _setFanMode(entity, mode),
|
||||||
Text("Fan mode", style: TextStyle(
|
caption: "Fan mode",
|
||||||
fontSize: entity.stateFontSize
|
value: _tmpFanMode,
|
||||||
)),
|
|
||||||
DropdownButton<String>(
|
|
||||||
value: "$_tmpFanMode",
|
|
||||||
iconSize: 30.0,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: entity.largeFontSize,
|
|
||||||
color: Colors.black,
|
|
||||||
),
|
|
||||||
items: entity.fanList.map((String value) {
|
|
||||||
return new DropdownMenuItem<String>(
|
|
||||||
value: value,
|
|
||||||
child: new Text(value),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
onChanged: (mode) => _setFanMode(entity, mode),
|
|
||||||
),
|
|
||||||
Container(height: entity.rowPadding,)
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Container(height: 0.0, width: 0.0);
|
return Container(height: 0.0, width: 0.0);
|
||||||
@ -549,29 +480,11 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
|
|
||||||
Widget _buildSwingControl(ClimateEntity entity) {
|
Widget _buildSwingControl(ClimateEntity entity) {
|
||||||
if (entity.supportSwingMode) {
|
if (entity.supportSwingMode) {
|
||||||
return Column(
|
return ModeSelectorWidget(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
onChange: (mode) => _setSwingMode(entity, mode),
|
||||||
children: <Widget>[
|
options: entity.swingList,
|
||||||
Text("Swing mode", style: TextStyle(
|
value: _tmpSwingMode,
|
||||||
fontSize: entity.stateFontSize
|
caption: "Swing mode"
|
||||||
)),
|
|
||||||
DropdownButton<String>(
|
|
||||||
value: "$_tmpSwingMode",
|
|
||||||
iconSize: 30.0,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: entity.largeFontSize,
|
|
||||||
color: Colors.black,
|
|
||||||
),
|
|
||||||
items: entity.swingList.map((String value) {
|
|
||||||
return new DropdownMenuItem<String>(
|
|
||||||
value: value,
|
|
||||||
child: new Text(value),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
onChanged: (mode) => _setSwingMode(entity, mode),
|
|
||||||
),
|
|
||||||
Container(height: entity.rowPadding,)
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Container(height: 0.0, width: 0.0);
|
return Container(height: 0.0, width: 0.0);
|
||||||
@ -584,10 +497,11 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text("Target temperature", style: TextStyle(
|
Text("Target temperature", style: TextStyle(
|
||||||
fontSize: entity.stateFontSize
|
fontSize: Entity.stateFontSize
|
||||||
)),
|
)),
|
||||||
TemperatureControlWidget(
|
TemperatureControlWidget(
|
||||||
value: _tmpTemperature,
|
value: _tmpTemperature,
|
||||||
|
fontColor: _showPending ? Colors.red : Colors.black,
|
||||||
onLargeDec: () => _temperatureDown(entity, 0.5),
|
onLargeDec: () => _temperatureDown(entity, 0.5),
|
||||||
onLargeInc: () => _temperatureUp(entity, 0.5),
|
onLargeInc: () => _temperatureUp(entity, 0.5),
|
||||||
onSmallDec: () => _temperatureDown(entity, 0.1),
|
onSmallDec: () => _temperatureDown(entity, 0.1),
|
||||||
@ -606,6 +520,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
controls.addAll(<Widget>[
|
controls.addAll(<Widget>[
|
||||||
TemperatureControlWidget(
|
TemperatureControlWidget(
|
||||||
value: _tmpTargetLow,
|
value: _tmpTargetLow,
|
||||||
|
fontColor: _showPending ? Colors.red : Colors.black,
|
||||||
onLargeDec: () => _targetLowDown(entity, 0.5),
|
onLargeDec: () => _targetLowDown(entity, 0.5),
|
||||||
onLargeInc: () => _targetLowUp(entity, 0.5),
|
onLargeInc: () => _targetLowUp(entity, 0.5),
|
||||||
onSmallDec: () => _targetLowDown(entity, 0.1),
|
onSmallDec: () => _targetLowDown(entity, 0.1),
|
||||||
@ -620,6 +535,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
controls.add(
|
controls.add(
|
||||||
TemperatureControlWidget(
|
TemperatureControlWidget(
|
||||||
value: _tmpTargetHigh,
|
value: _tmpTargetHigh,
|
||||||
|
fontColor: _showPending ? Colors.red : Colors.black,
|
||||||
onLargeDec: () => _targetHighDown(entity, 0.5),
|
onLargeDec: () => _targetHighDown(entity, 0.5),
|
||||||
onLargeInc: () => _targetHighUp(entity, 0.5),
|
onLargeInc: () => _targetHighUp(entity, 0.5),
|
||||||
onSmallDec: () => _targetHighDown(entity, 0.1),
|
onSmallDec: () => _targetHighDown(entity, 0.1),
|
||||||
@ -632,7 +548,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text("Target temperature range", style: TextStyle(
|
Text("Target temperature range", style: TextStyle(
|
||||||
fontSize: entity.stateFontSize
|
fontSize: Entity.stateFontSize
|
||||||
)),
|
)),
|
||||||
Row(
|
Row(
|
||||||
children: controls,
|
children: controls,
|
||||||
@ -650,7 +566,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
result.addAll(<Widget>[
|
result.addAll(<Widget>[
|
||||||
Text(
|
Text(
|
||||||
"$_tmpTargetHumidity%",
|
"$_tmpTargetHumidity%",
|
||||||
style: TextStyle(fontSize: entity.largeFontSize),
|
style: TextStyle(fontSize: Entity.largeFontSize),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Slider(
|
child: Slider(
|
||||||
@ -674,9 +590,9 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.fromLTRB(
|
padding: EdgeInsets.fromLTRB(
|
||||||
0.0, entity.rowPadding, 0.0, entity.rowPadding),
|
0.0, Entity.rowPadding, 0.0, Entity.rowPadding),
|
||||||
child: Text("Target humidity", style: TextStyle(
|
child: Text("Target humidity", style: TextStyle(
|
||||||
fontSize: entity.stateFontSize
|
fontSize: Entity.stateFontSize
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
@ -684,7 +600,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
|
|||||||
children: result,
|
children: result,
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
height: entity.rowPadding,
|
height: Entity.rowPadding,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@ -795,7 +711,7 @@ class _CoverControlWidgetState extends State<CoverControlWidget> {
|
|||||||
_resetVars(entity);
|
_resetVars(entity);
|
||||||
}
|
}
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.fromLTRB(entity.leftWidgetPadding, entity.rowPadding, entity.rightWidgetPadding, 0.0),
|
padding: EdgeInsets.fromLTRB(Entity.leftWidgetPadding, Entity.rowPadding, Entity.rightWidgetPadding, 0.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
@ -813,9 +729,9 @@ class _CoverControlWidgetState extends State<CoverControlWidget> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.fromLTRB(
|
padding: EdgeInsets.fromLTRB(
|
||||||
0.0, entity.rowPadding, 0.0, entity.rowPadding),
|
0.0, Entity.rowPadding, 0.0, Entity.rowPadding),
|
||||||
child: Text("Position", style: TextStyle(
|
child: Text("Position", style: TextStyle(
|
||||||
fontSize: entity.stateFontSize
|
fontSize: Entity.stateFontSize
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
Slider(
|
Slider(
|
||||||
@ -831,7 +747,7 @@ class _CoverControlWidgetState extends State<CoverControlWidget> {
|
|||||||
},
|
},
|
||||||
onChangeEnd: (double value) => _setNewPosition(entity, value),
|
onChangeEnd: (double value) => _setNewPosition(entity, value),
|
||||||
),
|
),
|
||||||
Container(height: entity.rowPadding,)
|
Container(height: Entity.rowPadding,)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -861,15 +777,15 @@ class _CoverControlWidgetState extends State<CoverControlWidget> {
|
|||||||
},
|
},
|
||||||
onChangeEnd: (double value) => _setNewTiltPosition(entity, value),
|
onChangeEnd: (double value) => _setNewTiltPosition(entity, value),
|
||||||
),
|
),
|
||||||
Container(height: entity.rowPadding,)
|
Container(height: Entity.rowPadding,)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
if (controls.isNotEmpty) {
|
if (controls.isNotEmpty) {
|
||||||
controls.insert(0, Padding(
|
controls.insert(0, Padding(
|
||||||
padding: EdgeInsets.fromLTRB(
|
padding: EdgeInsets.fromLTRB(
|
||||||
0.0, entity.rowPadding, 0.0, entity.rowPadding),
|
0.0, Entity.rowPadding, 0.0, Entity.rowPadding),
|
||||||
child: Text("Tilt position", style: TextStyle(
|
child: Text("Tilt position", style: TextStyle(
|
||||||
fontSize: entity.stateFontSize
|
fontSize: Entity.stateFontSize
|
||||||
)),
|
)),
|
||||||
));
|
));
|
||||||
return Column(
|
return Column(
|
||||||
|
@ -27,15 +27,16 @@ class DefaultEntityContainer extends StatelessWidget {
|
|||||||
DefaultEntityContainer({
|
DefaultEntityContainer({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.state,
|
@required this.state,
|
||||||
|
@required this.height
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final Widget state;
|
final Widget state;
|
||||||
|
final double height;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final entityModel = EntityModel.of(context);
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: entityModel.entity.widgetHeight,
|
height: height,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
EntityIcon(),
|
EntityIcon(),
|
||||||
@ -68,13 +69,13 @@ class SimpleEntityState extends StatelessWidget {
|
|||||||
final entityModel = EntityModel.of(context);
|
final entityModel = EntityModel.of(context);
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.fromLTRB(
|
padding: EdgeInsets.fromLTRB(
|
||||||
0.0, 0.0, entityModel.entity.rightWidgetPadding, 0.0),
|
0.0, 0.0, Entity.rightWidgetPadding, 0.0),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
child: Text(
|
child: Text(
|
||||||
"${entityModel.entity.state}${entityModel.entity.unitOfMeasurement}",
|
"${entityModel.entity.state}${entityModel.entity.unitOfMeasurement}",
|
||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
style: new TextStyle(
|
style: new TextStyle(
|
||||||
fontSize: entityModel.entity.stateFontSize,
|
fontSize: Entity.stateFontSize,
|
||||||
)),
|
)),
|
||||||
onTap: () => entityModel.handleTap
|
onTap: () => entityModel.handleTap
|
||||||
? eventBus.fire(new ShowEntityPageEvent(entityModel.entity))
|
? eventBus.fire(new ShowEntityPageEvent(entityModel.entity))
|
||||||
@ -94,7 +95,7 @@ class EntityName extends StatelessWidget {
|
|||||||
"${entityModel.entity.displayName}",
|
"${entityModel.entity.displayName}",
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
softWrap: false,
|
softWrap: false,
|
||||||
style: TextStyle(fontSize: entityModel.entity.nameFontSize),
|
style: TextStyle(fontSize: Entity.nameFontSize),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () => entityModel.handleTap
|
onTap: () => entityModel.handleTap
|
||||||
@ -111,11 +112,11 @@ class EntityIcon extends StatelessWidget {
|
|||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.fromLTRB(
|
padding: EdgeInsets.fromLTRB(
|
||||||
entityModel.entity.leftWidgetPadding, 0.0, 12.0, 0.0),
|
Entity.leftWidgetPadding, 0.0, 12.0, 0.0),
|
||||||
//TODO: move createIconWidgetFromEntityData into this widget
|
//TODO: move createIconWidgetFromEntityData into this widget
|
||||||
child: MaterialDesignIcons.createIconWidgetFromEntityData(
|
child: MaterialDesignIcons.createIconWidgetFromEntityData(
|
||||||
entityModel.entity,
|
entityModel.entity,
|
||||||
entityModel.entity.iconSize,
|
Entity.iconSize,
|
||||||
Entity.STATE_ICONS_COLORS[entityModel.entity.state] ??
|
Entity.STATE_ICONS_COLORS[entityModel.entity.state] ??
|
||||||
Entity.STATE_ICONS_COLORS["default"]),
|
Entity.STATE_ICONS_COLORS["default"]),
|
||||||
),
|
),
|
||||||
@ -132,12 +133,12 @@ class LastUpdatedWidget extends StatelessWidget {
|
|||||||
final entityModel = EntityModel.of(context);
|
final entityModel = EntityModel.of(context);
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.fromLTRB(
|
padding: EdgeInsets.fromLTRB(
|
||||||
entityModel.entity.leftWidgetPadding, 0.0, 0.0, 0.0),
|
Entity.leftWidgetPadding, 0.0, 0.0, 0.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
'${entityModel.entity.lastUpdated}',
|
'${entityModel.entity.lastUpdated}',
|
||||||
textAlign: TextAlign.left,
|
textAlign: TextAlign.left,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: entityModel.entity.smallFontSize, color: Colors.black26),
|
fontSize: Entity.smallFontSize, color: Colors.black26),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -153,14 +154,14 @@ class EntityAttributesList extends StatelessWidget {
|
|||||||
if ((entityModel.entity.attributesToShow == null) ||
|
if ((entityModel.entity.attributesToShow == null) ||
|
||||||
(entityModel.entity.attributesToShow.contains("all"))) {
|
(entityModel.entity.attributesToShow.contains("all"))) {
|
||||||
entityModel.entity.attributes.forEach((name, value) {
|
entityModel.entity.attributes.forEach((name, value) {
|
||||||
attrs.add(_buildSingleAttribute(entityModel.entity, "$name", "$value"));
|
attrs.add(_buildSingleAttribute("$name", "$value"));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
entityModel.entity.attributesToShow.forEach((String attr) {
|
entityModel.entity.attributesToShow.forEach((String attr) {
|
||||||
String attrValue = entityModel.entity.getAttribute("$attr");
|
String attrValue = entityModel.entity.getAttribute("$attr");
|
||||||
if (attrValue != null) {
|
if (attrValue != null) {
|
||||||
attrs.add(
|
attrs.add(
|
||||||
_buildSingleAttribute(entityModel.entity, "$attr", "$attrValue"));
|
_buildSingleAttribute("$attr", "$attrValue"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -171,13 +172,13 @@ class EntityAttributesList extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildSingleAttribute(Entity entity, String name, String value) {
|
Widget _buildSingleAttribute(String name, String value) {
|
||||||
return Row(
|
return Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.fromLTRB(
|
padding: EdgeInsets.fromLTRB(
|
||||||
entity.leftWidgetPadding, entity.rowPadding, 0.0, 0.0),
|
Entity.leftWidgetPadding, Entity.rowPadding, 0.0, 0.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
"$name",
|
"$name",
|
||||||
textAlign: TextAlign.left,
|
textAlign: TextAlign.left,
|
||||||
@ -187,7 +188,7 @@ class EntityAttributesList extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.fromLTRB(
|
padding: EdgeInsets.fromLTRB(
|
||||||
0.0, entity.rowPadding, entity.rightWidgetPadding, 0.0),
|
0.0, Entity.rowPadding, Entity.rightWidgetPadding, 0.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
"$value",
|
"$value",
|
||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
@ -341,7 +342,7 @@ class ClimateStateWidget extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.fromLTRB(
|
padding: EdgeInsets.fromLTRB(
|
||||||
0.0, 0.0, entityModel.entity.rightWidgetPadding, 0.0),
|
0.0, 0.0, Entity.rightWidgetPadding, 0.0),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
@ -353,12 +354,12 @@ class ClimateStateWidget extends StatelessWidget {
|
|||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
style: new TextStyle(
|
style: new TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: entityModel.entity.stateFontSize,
|
fontSize: Entity.stateFontSize,
|
||||||
)),
|
)),
|
||||||
Text(" $targetTemp",
|
Text(" $targetTemp",
|
||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
style: new TextStyle(
|
style: new TextStyle(
|
||||||
fontSize: entityModel.entity.stateFontSize,
|
fontSize: Entity.stateFontSize,
|
||||||
))
|
))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -366,7 +367,7 @@ class ClimateStateWidget extends StatelessWidget {
|
|||||||
Text("Currently: ${entity.attributes["current_temperature"]}",
|
Text("Currently: ${entity.attributes["current_temperature"]}",
|
||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
style: new TextStyle(
|
style: new TextStyle(
|
||||||
fontSize: entityModel.entity.stateFontSize,
|
fontSize: Entity.stateFontSize,
|
||||||
color: Colors.black45)
|
color: Colors.black45)
|
||||||
) :
|
) :
|
||||||
Container(height: 0.0,)
|
Container(height: 0.0,)
|
||||||
@ -454,12 +455,12 @@ class DateTimeStateWidget extends StatelessWidget {
|
|||||||
final entityModel = EntityModel.of(context);
|
final entityModel = EntityModel.of(context);
|
||||||
final DateTimeEntity entity = entityModel.entity;
|
final DateTimeEntity entity = entityModel.entity;
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.fromLTRB(0.0, 0.0, entity.rightWidgetPadding, 0.0),
|
padding: EdgeInsets.fromLTRB(0.0, 0.0, Entity.rightWidgetPadding, 0.0),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
child: Text("${entity.formattedState}",
|
child: Text("${entity.formattedState}",
|
||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
style: new TextStyle(
|
style: new TextStyle(
|
||||||
fontSize: entity.stateFontSize,
|
fontSize: Entity.stateFontSize,
|
||||||
)),
|
)),
|
||||||
onTap: () => _handleStateTap(context, entity),
|
onTap: () => _handleStateTap(context, entity),
|
||||||
));
|
));
|
||||||
@ -547,36 +548,36 @@ class CoverEntityControlState extends StatelessWidget {
|
|||||||
buttons.add(IconButton(
|
buttons.add(IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
MaterialDesignIcons.createIconDataFromIconName("mdi:arrow-up"),
|
MaterialDesignIcons.createIconDataFromIconName("mdi:arrow-up"),
|
||||||
size: entity.iconSize,
|
size: Entity.iconSize,
|
||||||
),
|
),
|
||||||
onPressed: entity.canBeOpened ? () => _open(entity) : null));
|
onPressed: entity.canBeOpened ? () => _open(entity) : null));
|
||||||
} else {
|
} else {
|
||||||
buttons.add(Container(
|
buttons.add(Container(
|
||||||
width: entity.iconSize + 20.0,
|
width: Entity.iconSize + 20.0,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if (entity.supportStop) {
|
if (entity.supportStop) {
|
||||||
buttons.add(IconButton(
|
buttons.add(IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
MaterialDesignIcons.createIconDataFromIconName("mdi:stop"),
|
MaterialDesignIcons.createIconDataFromIconName("mdi:stop"),
|
||||||
size: entity.iconSize,
|
size: Entity.iconSize,
|
||||||
),
|
),
|
||||||
onPressed: () => _stop(entity)));
|
onPressed: () => _stop(entity)));
|
||||||
} else {
|
} else {
|
||||||
buttons.add(Container(
|
buttons.add(Container(
|
||||||
width: entity.iconSize + 20.0,
|
width: Entity.iconSize + 20.0,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if (entity.supportClose) {
|
if (entity.supportClose) {
|
||||||
buttons.add(IconButton(
|
buttons.add(IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
MaterialDesignIcons.createIconDataFromIconName("mdi:arrow-down"),
|
MaterialDesignIcons.createIconDataFromIconName("mdi:arrow-down"),
|
||||||
size: entity.iconSize,
|
size: Entity.iconSize,
|
||||||
),
|
),
|
||||||
onPressed: entity.canBeClosed ? () => _close(entity) : null));
|
onPressed: entity.canBeClosed ? () => _close(entity) : null));
|
||||||
} else {
|
} else {
|
||||||
buttons.add(Container(
|
buttons.add(Container(
|
||||||
width: entity.iconSize + 20.0,
|
width: Entity.iconSize + 20.0,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,24 +613,24 @@ class CoverEntityTiltControlButtons extends StatelessWidget {
|
|||||||
icon: Icon(
|
icon: Icon(
|
||||||
MaterialDesignIcons.createIconDataFromIconName(
|
MaterialDesignIcons.createIconDataFromIconName(
|
||||||
"mdi:arrow-top-right"),
|
"mdi:arrow-top-right"),
|
||||||
size: entity.iconSize,
|
size: Entity.iconSize,
|
||||||
),
|
),
|
||||||
onPressed: entity.canTiltBeOpened ? () => _open(entity) : null));
|
onPressed: entity.canTiltBeOpened ? () => _open(entity) : null));
|
||||||
} else {
|
} else {
|
||||||
buttons.add(Container(
|
buttons.add(Container(
|
||||||
width: entity.iconSize + 20.0,
|
width: Entity.iconSize + 20.0,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if (entity.supportStopTilt) {
|
if (entity.supportStopTilt) {
|
||||||
buttons.add(IconButton(
|
buttons.add(IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
MaterialDesignIcons.createIconDataFromIconName("mdi:stop"),
|
MaterialDesignIcons.createIconDataFromIconName("mdi:stop"),
|
||||||
size: entity.iconSize,
|
size: Entity.iconSize,
|
||||||
),
|
),
|
||||||
onPressed: () => _stop(entity)));
|
onPressed: () => _stop(entity)));
|
||||||
} else {
|
} else {
|
||||||
buttons.add(Container(
|
buttons.add(Container(
|
||||||
width: entity.iconSize + 20.0,
|
width: Entity.iconSize + 20.0,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if (entity.supportCloseTilt) {
|
if (entity.supportCloseTilt) {
|
||||||
@ -637,12 +638,12 @@ class CoverEntityTiltControlButtons extends StatelessWidget {
|
|||||||
icon: Icon(
|
icon: Icon(
|
||||||
MaterialDesignIcons.createIconDataFromIconName(
|
MaterialDesignIcons.createIconDataFromIconName(
|
||||||
"mdi:arrow-bottom-left"),
|
"mdi:arrow-bottom-left"),
|
||||||
size: entity.iconSize,
|
size: Entity.iconSize,
|
||||||
),
|
),
|
||||||
onPressed: entity.canTiltBeClosed ? () => _close(entity) : null));
|
onPressed: entity.canTiltBeClosed ? () => _close(entity) : null));
|
||||||
} else {
|
} else {
|
||||||
buttons.add(Container(
|
buttons.add(Container(
|
||||||
width: entity.iconSize + 20.0,
|
width: Entity.iconSize + 20.0,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,3 +652,90 @@ class CoverEntityTiltControlButtons extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ModeSelectorWidget extends StatelessWidget {
|
||||||
|
|
||||||
|
final String caption;
|
||||||
|
final List<String> options;
|
||||||
|
final String value;
|
||||||
|
final double captionFontSize;
|
||||||
|
final double valueFontSize;
|
||||||
|
final double bottomPadding;
|
||||||
|
final onChange;
|
||||||
|
|
||||||
|
ModeSelectorWidget({
|
||||||
|
Key key,
|
||||||
|
this.caption,
|
||||||
|
@required this.options,
|
||||||
|
this.value,
|
||||||
|
@required this.onChange,
|
||||||
|
this.captionFontSize,
|
||||||
|
this.valueFontSize,
|
||||||
|
this.bottomPadding
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
Text("$caption", style: TextStyle(
|
||||||
|
fontSize: captionFontSize ?? Entity.stateFontSize
|
||||||
|
)),
|
||||||
|
DropdownButton<String>(
|
||||||
|
value: "$value",
|
||||||
|
iconSize: 30.0,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: valueFontSize ?? Entity.largeFontSize,
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
items: options.map((String value) {
|
||||||
|
return new DropdownMenuItem<String>(
|
||||||
|
value: value,
|
||||||
|
child: new Text(value),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
onChanged: (mode) => onChange(mode),
|
||||||
|
),
|
||||||
|
Container(height: bottomPadding ?? Entity.rowPadding,)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ModeSwitchWidget extends StatelessWidget {
|
||||||
|
|
||||||
|
final String caption;
|
||||||
|
final onChange;
|
||||||
|
final double captionFontSize;
|
||||||
|
final bool value;
|
||||||
|
|
||||||
|
ModeSwitchWidget({
|
||||||
|
Key key,
|
||||||
|
@required this.caption,
|
||||||
|
@required this.onChange,
|
||||||
|
this.captionFontSize,
|
||||||
|
this.value
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
"$caption",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: captionFontSize ?? Entity.stateFontSize
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Switch(
|
||||||
|
onChanged: (value) => onChange(value),
|
||||||
|
value: value ?? false,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user