This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/entity_widgets/state/simple_state.dart

54 lines
1.5 KiB
Dart
Raw Normal View History

2018-10-27 14:27:41 +03:00
part of '../../main.dart';
class SimpleEntityState extends StatelessWidget {
2018-11-05 20:21:44 +02:00
final bool expanded;
2018-11-14 19:52:17 +02:00
final TextAlign textAlign;
final EdgeInsetsGeometry padding;
2018-11-25 20:44:19 +02:00
final int maxLines;
2019-03-13 21:33:58 +02:00
final String customValue;
2018-11-05 20:21:44 +02:00
2019-03-13 21:33:58 +02:00
const SimpleEntityState({Key key, this.maxLines: 10, this.expanded: true, this.textAlign: TextAlign.right, this.padding: const EdgeInsets.fromLTRB(0.0, 0.0, Sizes.rightWidgetPadding, 0.0), this.customValue}) : super(key: key);
2018-11-05 20:21:44 +02:00
2018-10-27 14:27:41 +03:00
@override
Widget build(BuildContext context) {
final entityModel = EntityModel.of(context);
2019-03-13 21:33:58 +02:00
String state;
if (customValue == null) {
state = entityModel.entityWrapper.entity.displayState ?? "";
state = state.replaceAll("\n", "").replaceAll("\t", " ").trim();
} else {
state = customValue;
}
2019-03-13 14:08:54 +02:00
TextStyle textStyle = TextStyle(
fontSize: Sizes.stateFontSize,
);
if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.CALL_SERVICE) {
textStyle = textStyle.apply(color: Colors.blue);
}
while (state.contains(" ")){
state = state.replaceAll(" ", " ");
}
2018-11-05 20:21:44 +02:00
Widget result = Padding(
2018-11-24 00:37:55 +02:00
padding: padding,
child: Text(
"$state ${entityModel.entityWrapper.entity.unitOfMeasurement}",
2018-11-24 00:37:55 +02:00
textAlign: textAlign,
2018-11-25 20:44:19 +02:00
maxLines: maxLines,
2018-11-24 00:37:55 +02:00
overflow: TextOverflow.ellipsis,
softWrap: true,
2019-03-13 14:08:54 +02:00
style: textStyle
2018-11-24 00:37:55 +02:00
)
2018-11-04 22:55:09 +02:00
);
2018-11-05 20:21:44 +02:00
if (expanded) {
2018-11-18 16:40:12 +02:00
return Flexible(
fit: FlexFit.tight,
flex: 2,
2018-11-14 12:35:08 +02:00
child: result,
2018-11-05 20:21:44 +02:00
);
} else {
return result;
}
2018-10-27 14:27:41 +03:00
}
2018-11-04 22:55:09 +02:00
}