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;
|
2019-09-07 17:04:40 +03:00
|
|
|
final double fontSize;
|
|
|
|
final bool bold;
|
2018-11-05 20:21:44 +02:00
|
|
|
|
2019-09-07 17:04:40 +03:00
|
|
|
const SimpleEntityState({Key key,this.bold: false, this.maxLines: 10, this.fontSize: Sizes.stateFontSize, 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(
|
2019-09-07 17:04:40 +03:00
|
|
|
fontSize: this.fontSize,
|
|
|
|
fontWeight: FontWeight.normal
|
2019-03-13 14:08:54 +02:00
|
|
|
);
|
|
|
|
if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.CALL_SERVICE) {
|
|
|
|
textStyle = textStyle.apply(color: Colors.blue);
|
|
|
|
}
|
2019-09-07 17:04:40 +03:00
|
|
|
if (this.bold) {
|
|
|
|
textStyle = textStyle.apply(fontWeightDelta: 100);
|
|
|
|
}
|
2018-12-14 16:48:35 +02: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,
|
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
|
|
|
}
|