WIP #206 Entity button card

This commit is contained in:
Yegor Vialov 2018-11-25 17:33:33 +02:00
parent 4492fb9f0c
commit 5633e30448
9 changed files with 124 additions and 39 deletions

View File

@ -91,13 +91,6 @@ class Entity {
);
}
Widget buildGlanceWidget(BuildContext context, bool showName, bool showState) {
return GlanceEntityContainer(
showName: showName,
showState: showState,
);
}
Widget _buildStatePart(BuildContext context) {
return SimpleEntityState();
}

View File

@ -4,51 +4,97 @@ class GlanceEntityContainer extends StatelessWidget {
final bool showName;
final bool showState;
final bool nameInTheBottom;
final double iconSize;
final double nameFontSize;
final bool expanded;
GlanceEntityContainer({
Key key, @required this.showName, @required this.showState,
Key key,
@required this.showName,
@required this.showState,
this.nameInTheBottom: false,
this.iconSize: Sizes.iconSize,
this.nameFontSize: Sizes.smallFontSize,
this.expanded: false
}) : super(key: key);
@override
Widget build(BuildContext context) {
final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper;
List<Widget> result = [];
if (showName) {
if (!nameInTheBottom) {
if (showName) {
result.add(EntityName(
padding: EdgeInsets.only(bottom: Sizes.rowPadding),
textOverflow: TextOverflow.ellipsis,
wordsWrap: false,
textAlign: TextAlign.center,
fontSize: nameFontSize,
));
}
} else {
if (showState) {
result.add(SimpleEntityState(
textAlign: TextAlign.center,
expanded: false,
padding: EdgeInsets.only(top: Sizes.rowPadding),
));
}
}
result.add(
EntityIcon(
padding: EdgeInsets.all(0.0),
iconSize: iconSize,
)
);
if (!nameInTheBottom) {
if (showState) {
result.add(SimpleEntityState(
textAlign: TextAlign.center,
expanded: false,
padding: EdgeInsets.only(top: Sizes.rowPadding),
));
}
} else {
result.add(EntityName(
padding: EdgeInsets.only(bottom: Sizes.rowPadding),
textOverflow: TextOverflow.ellipsis,
wordsWrap: false,
textAlign: TextAlign.center,
fontSize: Sizes.smallFontSize,
fontSize: nameFontSize,
));
}
result.add(
EntityIcon(
padding: EdgeInsets.all(0.0),
iconSize: Sizes.iconSize,
)
);
if (showState) {
result.add(SimpleEntityState(
textAlign: TextAlign.center,
expanded: false,
padding: EdgeInsets.only(top: Sizes.rowPadding),
));
}
return Center(
child: InkResponse(
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: Sizes.iconSize*2),
if (expanded) {
return Container(
child: InkWell(
child: Column(
mainAxisSize: MainAxisSize.min,
//mainAxisAlignment: MainAxisAlignment.start,
//crossAxisAlignment: CrossAxisAlignment.center,
children: result,
),
onTap: () => entityWrapper.handleTap(),
onLongPress: () => entityWrapper.handleHold(),
),
onTap: () => entityWrapper.handleTap(),
onLongPress: () => entityWrapper.handleHold(),
),
);
);
} else {
return Center(
child: InkResponse(
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: Sizes.iconSize * 2),
child: Column(
mainAxisSize: MainAxisSize.min,
//mainAxisAlignment: MainAxisAlignment.start,
//crossAxisAlignment: CrossAxisAlignment.center,
children: result,
),
),
onTap: () => entityWrapper.handleTap(),
onLongPress: () => entityWrapper.handleHold(),
),
);
}
}
}

View File

@ -433,7 +433,7 @@ class HomeAssistant {
} else {
HACard card = HACard(
id: "card",
name: rawCard["title"],
name: rawCard["title"] ?? rawCard["name"],
type: rawCard['type'],
columnsCount: rawCard['columns'] ?? 4,
showName: rawCard['show_name'] ?? true,

View File

@ -80,6 +80,7 @@ part 'ui_class/sizes_class.dart';
part 'ui_widgets/view.dart';
part 'ui_widgets/entities_card.dart';
part 'ui_widgets/glance_card.dart';
part 'ui_widgets/entity_button_card.dart';
part 'ui_widgets/unsupported_card.dart';
part 'ui_widgets/media_control_card.dart';
part 'ui_widgets/card_header_widget.dart';

View File

@ -41,6 +41,12 @@ class HACard {
);
}
case CardType.entityButton: {
return EntityButtonCardWidget(
card: this,
);
}
case CardType.weatherForecast:
case CardType.thermostat:
case CardType.sensor:
@ -51,7 +57,6 @@ class HACard {
case CardType.map:
case CardType.iframe:
case CardType.gauge:
case CardType.entityButton:
case CardType.conditional:
case CardType.alarmPanel: {
return UnsupportedCardWidget(

View File

@ -5,7 +5,7 @@ class Sizes {
static const leftWidgetPadding = 8.0;
static const extendedWidgetHeight = 50.0;
static const iconSize = 28.0;
static const largeIconSize = 34.0;
static const largeIconSize = 46.0;
static const stateFontSize = 15.0;
static const nameFontSize = 15.0;
static const smallFontSize = 14.0;

View File

@ -0,0 +1,37 @@
part of '../main.dart';
class EntityButtonCardWidget extends StatelessWidget {
final HACard card;
const EntityButtonCardWidget({
Key key,
this.card
}) : super(key: key);
@override
Widget build(BuildContext context) {
if (card.linkedEntity!= null && card.linkedEntity.entity.isHidden) {
return Container(width: 0.0, height: 0.0,);
}
card.linkedEntity.displayName = card.name;
return Card(
child: Padding(
padding: EdgeInsets.fromLTRB(Sizes.leftWidgetPadding, Sizes.rowPadding, Sizes.rightWidgetPadding, Sizes.rowPadding),
child: EntityModel(
entityWrapper: card.linkedEntity,
child: GlanceEntityContainer(
showName: true,
showState: false,
nameInTheBottom: true,
iconSize: Sizes.largeIconSize,
nameFontSize: Sizes.nameFontSize,
expanded: true,
),
handleTap: true
),
)
);
}
}

View File

@ -33,7 +33,10 @@ class GlanceCardWidget extends StatelessWidget {
widthFactor: 1/columnsCount,
child: EntityModel(
entityWrapper: entity,
child: entity.entity.buildGlanceWidget(context, card.showName, card.showState),
child: GlanceEntityContainer(
showName: card.showName,
showState: card.showState,
),
handleTap: true
),
)

View File

@ -35,7 +35,7 @@ packages:
name: cached_network_image
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0+1"
version: "0.5.1"
charcode:
dependency: transitive
description:
@ -83,7 +83,7 @@ packages:
description:
path: "."
ref: HEAD
resolved-ref: c5727795659e886a7db8b39a14e2c8987280fe1f
resolved-ref: e26916e095244a7e5ea61315b030d298d127ed26
url: "https://github.com/MarkOSullivan94/dart_config.git"
source: git
version: "0.5.0"
@ -126,7 +126,7 @@ packages:
name: flutter_launcher_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.1"
version: "0.7.0"
flutter_test:
dependency: "direct dev"
description: flutter
@ -327,5 +327,5 @@ packages:
source: hosted
version: "2.1.15"
sdks:
dart: ">=2.0.0 <=2.1.0-dev.9.3.flutter-9c07fb64c4"
dart: ">=2.0.0 <3.0.0"
flutter: ">=0.5.6 <2.0.0"