WIP #206 Entity button card
This commit is contained in:
parent
4492fb9f0c
commit
5633e30448
@ -91,13 +91,6 @@ class Entity {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildGlanceWidget(BuildContext context, bool showName, bool showState) {
|
|
||||||
return GlanceEntityContainer(
|
|
||||||
showName: showName,
|
|
||||||
showState: showState,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildStatePart(BuildContext context) {
|
Widget _buildStatePart(BuildContext context) {
|
||||||
return SimpleEntityState();
|
return SimpleEntityState();
|
||||||
}
|
}
|
||||||
|
@ -4,30 +4,36 @@ class GlanceEntityContainer extends StatelessWidget {
|
|||||||
|
|
||||||
final bool showName;
|
final bool showName;
|
||||||
final bool showState;
|
final bool showState;
|
||||||
|
final bool nameInTheBottom;
|
||||||
|
final double iconSize;
|
||||||
|
final double nameFontSize;
|
||||||
|
final bool expanded;
|
||||||
|
|
||||||
GlanceEntityContainer({
|
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);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper;
|
final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper;
|
||||||
List<Widget> result = [];
|
List<Widget> result = [];
|
||||||
|
if (!nameInTheBottom) {
|
||||||
if (showName) {
|
if (showName) {
|
||||||
result.add(EntityName(
|
result.add(EntityName(
|
||||||
padding: EdgeInsets.only(bottom: Sizes.rowPadding),
|
padding: EdgeInsets.only(bottom: Sizes.rowPadding),
|
||||||
textOverflow: TextOverflow.ellipsis,
|
textOverflow: TextOverflow.ellipsis,
|
||||||
wordsWrap: false,
|
wordsWrap: false,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
fontSize: Sizes.smallFontSize,
|
fontSize: nameFontSize,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
result.add(
|
} else {
|
||||||
EntityIcon(
|
|
||||||
padding: EdgeInsets.all(0.0),
|
|
||||||
iconSize: Sizes.iconSize,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (showState) {
|
if (showState) {
|
||||||
result.add(SimpleEntityState(
|
result.add(SimpleEntityState(
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
@ -35,10 +41,49 @@ class GlanceEntityContainer extends StatelessWidget {
|
|||||||
padding: EdgeInsets.only(top: Sizes.rowPadding),
|
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: nameFontSize,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
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(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
return Center(
|
return Center(
|
||||||
child: InkResponse(
|
child: InkResponse(
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: BoxConstraints(minWidth: Sizes.iconSize*2),
|
constraints: BoxConstraints(minWidth: Sizes.iconSize * 2),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
//mainAxisAlignment: MainAxisAlignment.start,
|
//mainAxisAlignment: MainAxisAlignment.start,
|
||||||
@ -51,4 +96,5 @@ class GlanceEntityContainer extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -433,7 +433,7 @@ class HomeAssistant {
|
|||||||
} else {
|
} else {
|
||||||
HACard card = HACard(
|
HACard card = HACard(
|
||||||
id: "card",
|
id: "card",
|
||||||
name: rawCard["title"],
|
name: rawCard["title"] ?? rawCard["name"],
|
||||||
type: rawCard['type'],
|
type: rawCard['type'],
|
||||||
columnsCount: rawCard['columns'] ?? 4,
|
columnsCount: rawCard['columns'] ?? 4,
|
||||||
showName: rawCard['show_name'] ?? true,
|
showName: rawCard['show_name'] ?? true,
|
||||||
|
@ -80,6 +80,7 @@ part 'ui_class/sizes_class.dart';
|
|||||||
part 'ui_widgets/view.dart';
|
part 'ui_widgets/view.dart';
|
||||||
part 'ui_widgets/entities_card.dart';
|
part 'ui_widgets/entities_card.dart';
|
||||||
part 'ui_widgets/glance_card.dart';
|
part 'ui_widgets/glance_card.dart';
|
||||||
|
part 'ui_widgets/entity_button_card.dart';
|
||||||
part 'ui_widgets/unsupported_card.dart';
|
part 'ui_widgets/unsupported_card.dart';
|
||||||
part 'ui_widgets/media_control_card.dart';
|
part 'ui_widgets/media_control_card.dart';
|
||||||
part 'ui_widgets/card_header_widget.dart';
|
part 'ui_widgets/card_header_widget.dart';
|
||||||
|
@ -41,6 +41,12 @@ class HACard {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case CardType.entityButton: {
|
||||||
|
return EntityButtonCardWidget(
|
||||||
|
card: this,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
case CardType.weatherForecast:
|
case CardType.weatherForecast:
|
||||||
case CardType.thermostat:
|
case CardType.thermostat:
|
||||||
case CardType.sensor:
|
case CardType.sensor:
|
||||||
@ -51,7 +57,6 @@ class HACard {
|
|||||||
case CardType.map:
|
case CardType.map:
|
||||||
case CardType.iframe:
|
case CardType.iframe:
|
||||||
case CardType.gauge:
|
case CardType.gauge:
|
||||||
case CardType.entityButton:
|
|
||||||
case CardType.conditional:
|
case CardType.conditional:
|
||||||
case CardType.alarmPanel: {
|
case CardType.alarmPanel: {
|
||||||
return UnsupportedCardWidget(
|
return UnsupportedCardWidget(
|
||||||
|
@ -5,7 +5,7 @@ class Sizes {
|
|||||||
static const leftWidgetPadding = 8.0;
|
static const leftWidgetPadding = 8.0;
|
||||||
static const extendedWidgetHeight = 50.0;
|
static const extendedWidgetHeight = 50.0;
|
||||||
static const iconSize = 28.0;
|
static const iconSize = 28.0;
|
||||||
static const largeIconSize = 34.0;
|
static const largeIconSize = 46.0;
|
||||||
static const stateFontSize = 15.0;
|
static const stateFontSize = 15.0;
|
||||||
static const nameFontSize = 15.0;
|
static const nameFontSize = 15.0;
|
||||||
static const smallFontSize = 14.0;
|
static const smallFontSize = 14.0;
|
||||||
|
37
lib/ui_widgets/entity_button_card.dart
Normal file
37
lib/ui_widgets/entity_button_card.dart
Normal 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
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -33,7 +33,10 @@ class GlanceCardWidget extends StatelessWidget {
|
|||||||
widthFactor: 1/columnsCount,
|
widthFactor: 1/columnsCount,
|
||||||
child: EntityModel(
|
child: EntityModel(
|
||||||
entityWrapper: entity,
|
entityWrapper: entity,
|
||||||
child: entity.entity.buildGlanceWidget(context, card.showName, card.showState),
|
child: GlanceEntityContainer(
|
||||||
|
showName: card.showName,
|
||||||
|
showState: card.showState,
|
||||||
|
),
|
||||||
handleTap: true
|
handleTap: true
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -35,7 +35,7 @@ packages:
|
|||||||
name: cached_network_image
|
name: cached_network_image
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.5.0+1"
|
version: "0.5.1"
|
||||||
charcode:
|
charcode:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -83,7 +83,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: HEAD
|
ref: HEAD
|
||||||
resolved-ref: c5727795659e886a7db8b39a14e2c8987280fe1f
|
resolved-ref: e26916e095244a7e5ea61315b030d298d127ed26
|
||||||
url: "https://github.com/MarkOSullivan94/dart_config.git"
|
url: "https://github.com/MarkOSullivan94/dart_config.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.5.0"
|
version: "0.5.0"
|
||||||
@ -126,7 +126,7 @@ packages:
|
|||||||
name: flutter_launcher_icons
|
name: flutter_launcher_icons
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.6.1"
|
version: "0.7.0"
|
||||||
flutter_test:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
@ -327,5 +327,5 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.15"
|
version: "2.1.15"
|
||||||
sdks:
|
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"
|
flutter: ">=0.5.6 <2.0.0"
|
||||||
|
Reference in New Issue
Block a user