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

44 lines
1.2 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;
2018-11-05 20:21:44 +02:00
2018-11-25 20:44:19 +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)}) : 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);
2018-12-15 14:37:00 +02:00
String state = entityModel.entityWrapper.entity.displayState ?? "";
state = state.replaceAll("\n", "").replaceAll("\t", " ").trim();
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,
style: new TextStyle(
fontSize: Sizes.stateFontSize,
2018-11-05 20:21:44 +02:00
)
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
}