WIP #416 Vacuum support
This commit is contained in:
104
lib/entities/vacuum/widgets/vacuum_controls.dart
Normal file
104
lib/entities/vacuum/widgets/vacuum_controls.dart
Normal file
@ -0,0 +1,104 @@
|
||||
part of '../../../main.dart';
|
||||
|
||||
class VacuumControls extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
VacuumEntity entity = EntityModel.of(context).entityWrapper.entity;
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: Sizes.leftWidgetPadding, right: Sizes.rightWidgetPadding),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
_buildStatusAndBattery(entity),
|
||||
_buildCommands(entity)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusAndBattery(VacuumEntity entity) {
|
||||
List<Widget> result = [];
|
||||
if (entity.supportStatus) {
|
||||
result.addAll(
|
||||
<Widget>[
|
||||
Text("Status:", style: TextStyle(fontSize: Sizes.stateFontSize),),
|
||||
Container(width: 6,),
|
||||
Expanded(
|
||||
//flex: 1,
|
||||
child: Text(
|
||||
"${entity.status}",
|
||||
maxLines: 1,
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: Sizes.stateFontSize,
|
||||
fontWeight: FontWeight.bold
|
||||
),
|
||||
),
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
if (entity.supportBattery && entity.batteryLevel != null) {
|
||||
String iconName = entity.batteryIcon ?? "mdi:battery";
|
||||
int batteryLevel = entity.batteryLevel ?? 100;
|
||||
result.addAll(<Widget>[
|
||||
Icon(MaterialDesignIcons.getIconDataFromIconName(iconName)),
|
||||
Container(width: 6,),
|
||||
Text("$batteryLevel %", style: TextStyle(fontSize: Sizes.stateFontSize))
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (result.isEmpty) {
|
||||
return Container(width: 0, height: 0);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: Sizes.rowPadding),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: result,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCommands(VacuumEntity entity) {
|
||||
List<Widget> commandButtons = [];
|
||||
double iconSize = 32;
|
||||
if (entity.supportPause) {
|
||||
commandButtons.add(
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:play-pause")),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => Logger.d("[VACUUM] pause"),
|
||||
)
|
||||
);
|
||||
}
|
||||
if (entity.supportStop) {
|
||||
commandButtons.add(
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:stop")),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => Logger.d("[VACUUM] stop"),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text("Vacuum cleaner commands:", style: TextStyle(fontSize: Sizes.stateFontSize)),
|
||||
Container(height: Sizes.rowPadding,),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: commandButtons,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user