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

73 lines
1.9 KiB
Dart
Raw Normal View History

2018-10-27 14:27:41 +03:00
part of '../main.dart';
class DefaultEntityContainer extends StatelessWidget {
DefaultEntityContainer({
Key key,
2018-11-04 22:57:53 +02:00
@required this.state
2018-10-27 14:27:41 +03:00
}) : super(key: key);
final Widget state;
@override
Widget build(BuildContext context) {
2018-11-24 00:37:55 +02:00
final EntityModel entityModel = EntityModel.of(context);
if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.MISSED) {
2019-03-12 23:35:33 +02:00
return MissedEntityWidget();
}
if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.DIVIDER) {
2020-04-07 00:39:16 +03:00
return Divider();
}
if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.SECTION) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
2020-04-07 00:39:16 +03:00
Divider(),
Text(
"${entityModel.entityWrapper.entity.displayName}",
style: Theme.of(context).textTheme.body1.copyWith(
2020-04-07 00:39:16 +03:00
color: Theme.of(context).primaryColor
),
)
],
2019-03-12 23:35:33 +02:00
);
}
Widget result = Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
EntityIcon(),
Flexible(
fit: FlexFit.tight,
flex: 3,
child: EntityName(
padding: EdgeInsets.fromLTRB(10.0, 2.0, 10.0, 2.0),
),
),
state
],
);
if (entityModel.handleTap) {
return InkWell(
onLongPress: () {
if (entityModel.handleTap) {
entityModel.entityWrapper.handleHold();
}
},
onTap: () {
if (entityModel.handleTap) {
entityModel.entityWrapper.handleTap();
}
},
2020-03-14 20:12:11 +02:00
onDoubleTap: () {
if (entityModel.handleTap) {
entityModel.entityWrapper.handleDoubleTap();
}
},
child: result,
);
} else {
return result;
}
2018-10-27 14:27:41 +03:00
}
}