From 78dd7df6865b6e40e1d2023adf424a2573296b97 Mon Sep 17 00:00:00 2001 From: estevez-dev Date: Sat, 14 Sep 2019 19:12:11 +0300 Subject: [PATCH] Entity class refactoring --- lib/entities/entity.class.dart | 6 ------ lib/entities/entity_page_layout.widget.dart | 2 +- lib/plugins/history_chart/entity_history.dart | 19 +++++++++---------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/entities/entity.class.dart b/lib/entities/entity.class.dart index 14197b0..2f335d8 100644 --- a/lib/entities/entity.class.dart +++ b/lib/entities/entity.class.dart @@ -211,12 +211,6 @@ class Entity { ); } - Widget buildHistoryWidget() { - return EntityHistoryWidget( - config: historyConfig, - ); - } - Widget buildBadgeWidget(BuildContext context) { return EntityModel( entityWrapper: EntityWrapper(entity: this), diff --git a/lib/entities/entity_page_layout.widget.dart b/lib/entities/entity_page_layout.widget.dart index 2ce6793..b3a01d4 100644 --- a/lib/entities/entity_page_layout.widget.dart +++ b/lib/entities/entity_page_layout.widget.dart @@ -54,7 +54,7 @@ class EntityPageLayout extends StatelessWidget { Divider(), this.entity._buildAdditionalControlsForPage(context), Divider(), - this.entity.buildHistoryWidget(), + EntityHistoryWidget(), EntityAttributesList() ] ), diff --git a/lib/plugins/history_chart/entity_history.dart b/lib/plugins/history_chart/entity_history.dart index d902df7..14dec4c 100644 --- a/lib/plugins/history_chart/entity_history.dart +++ b/lib/plugins/history_chart/entity_history.dart @@ -17,9 +17,7 @@ class EntityHistoryConfig { class EntityHistoryWidget extends StatefulWidget { - final EntityHistoryConfig config; - - const EntityHistoryWidget({Key key, @required this.config}) : super(key: key); + const EntityHistoryWidget({Key key}) : super(key: key); @override _EntityHistoryWidgetState createState() { @@ -33,6 +31,7 @@ class _EntityHistoryWidgetState extends State { bool _needToUpdateHistory; DateTime _historyLastUpdated; bool _disposed = false; + Entity entity; @override void initState() { @@ -75,10 +74,10 @@ class _EntityHistoryWidgetState extends State { } else { _loadHistory(entity.entityId); } - return _buildChart(); + return _buildChart(entity.historyConfig); } - Widget _buildChart() { + Widget _buildChart(EntityHistoryConfig config) { List children = []; if (_history == null) { children.add( @@ -90,7 +89,7 @@ class _EntityHistoryWidgetState extends State { ); } else { children.add( - _selectChartWidget() + _selectChartWidget(config) ); } children.add(Divider()); @@ -102,8 +101,8 @@ class _EntityHistoryWidgetState extends State { ); } - Widget _selectChartWidget() { - switch (widget.config.chartType) { + Widget _selectChartWidget(EntityHistoryConfig config) { + switch (config.chartType) { case EntityHistoryWidgetType.simple: { return SimpleStateHistoryChartWidget( @@ -114,14 +113,14 @@ class _EntityHistoryWidgetState extends State { case EntityHistoryWidgetType.numericState: { return NumericStateHistoryChartWidget( rawHistory: _history, - config: widget.config, + config: config, ); } case EntityHistoryWidgetType.numericAttributes: { return CombinedHistoryChartWidget( rawHistory: _history, - config: widget.config, + config: config, ); }