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/entities/simple_state.widget.dart

63 lines
1.8 KiB
Dart
Raw Normal View History

2019-09-09 18:50:35 +03:00
part of '../main.dart';
2018-10-27 14:27:41 +03:00
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;
2020-04-07 23:20:57 +03:00
final TextStyle textStyle;
2020-04-04 15:47:40 +03:00
//final bool bold;
2018-11-05 20:21:44 +02:00
2020-04-07 23:20:57 +03:00
const SimpleEntityState({Key key,/*this.bold: false,*/ this.maxLines: 10, this.expanded: true, this.textAlign: TextAlign.right, this.textStyle, 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;
}
2020-04-07 23:20:57 +03:00
TextStyle tStyle;
if (textStyle != null) {
tStyle = textStyle;
} else if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.callService) {
2020-04-07 23:20:57 +03:00
tStyle = Theme.of(context).textTheme.subhead.copyWith(
2020-04-29 23:11:37 +03:00
color: HAClientTheme().getLinkTextStyle(context).color
2020-04-04 15:47:40 +03:00
);
} else {
2020-04-07 23:20:57 +03:00
tStyle = Theme.of(context).textTheme.body1;
2019-03-13 14:08:54 +02:00
}
2020-04-04 15:47:40 +03:00
/*if (this.bold) {
2019-09-07 17:04:40 +03:00
textStyle = textStyle.apply(fontWeightDelta: 100);
2020-04-04 15:47:40 +03:00
}*/
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(
2019-09-07 17:04:40 +03:00
"$state ${entityModel.entityWrapper.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,
2020-04-07 23:20:57 +03:00
style: tStyle
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
}