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/main.dart

637 lines
20 KiB
Dart
Raw Normal View History

2018-09-10 00:34:52 +03:00
import 'dart:convert';
import 'dart:async';
import 'package:flutter/rendering.dart';
2018-09-10 00:34:52 +03:00
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:web_socket_channel/io.dart';
import 'package:event_bus/event_bus.dart';
2018-09-16 19:24:26 +03:00
import 'package:flutter/widgets.dart';
import 'package:cached_network_image/cached_network_image.dart';
2018-09-24 22:12:56 +03:00
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/services.dart';
2018-09-29 16:19:01 +03:00
import 'package:date_format/date_format.dart';
2018-10-07 23:06:06 +03:00
import 'package:http/http.dart' as http;
2018-10-17 02:19:46 +03:00
import 'package:flutter_colorpicker/material_picker.dart';
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:progress_indicators/progress_indicators.dart';
2018-11-14 15:14:46 +02:00
part 'entity_class/const.dart';
2018-10-27 14:27:41 +03:00
part 'entity_class/entity.class.dart';
2018-11-15 19:08:47 +02:00
part 'entity_class/entity_wrapper.class.dart';
2018-10-27 14:27:41 +03:00
part 'entity_class/switch_entity.class.dart';
part 'entity_class/button_entity.class.dart';
part 'entity_class/text_entity.class.dart';
part 'entity_class/climate_entity.class.dart';
part 'entity_class/cover_entity.class.dart';
part 'entity_class/date_time_entity.class.dart';
part 'entity_class/light_entity.class.dart';
part 'entity_class/select_entity.class.dart';
2018-10-28 20:01:01 +02:00
part 'entity_class/other_entity.class.dart';
part 'entity_class/slider_entity.dart';
2018-11-04 18:20:06 +02:00
part 'entity_class/media_player_entity.class.dart';
2018-11-23 19:18:17 +02:00
part 'entity_class/lock_entity.class.dart';
2018-11-17 22:40:33 +02:00
part 'entity_widgets/common/badge.dart';
part 'entity_widgets/model_widgets.dart';
2018-10-27 14:27:41 +03:00
part 'entity_widgets/default_entity_container.dart';
2018-11-14 19:52:17 +02:00
part 'entity_widgets/glance_entity_container.dart';
2018-11-17 22:40:33 +02:00
part 'entity_widgets/common/entity_attributes_list.dart';
2018-10-27 14:27:41 +03:00
part 'entity_widgets/entity_icon.dart';
part 'entity_widgets/entity_name.dart';
2018-11-17 22:40:33 +02:00
part 'entity_widgets/common/last_updated.dart';
part 'entity_widgets/common/mode_swicth.dart';
part 'entity_widgets/common/mode_selector.dart';
part 'entity_widgets/common/universal_slider.dart';
2018-10-28 21:02:38 +02:00
part 'entity_widgets/entity_colors.class.dart';
2018-10-27 14:27:41 +03:00
part 'entity_widgets/entity_page_container.dart';
2018-10-28 18:07:52 +02:00
part 'entity_widgets/history_chart/entity_history.dart';
part 'entity_widgets/history_chart/simple_state_history_chart.dart';
2018-10-28 20:01:01 +02:00
part 'entity_widgets/history_chart/numeric_state_history_chart.dart';
part 'entity_widgets/history_chart/combined_history_chart.dart';
2018-11-03 22:50:21 +02:00
part 'entity_widgets/history_chart/history_control_widget.dart';
part 'entity_widgets/history_chart/entity_history_moment.dart';
2018-10-27 14:27:41 +03:00
part 'entity_widgets/state/switch_state.dart';
2018-11-15 15:57:17 +02:00
part 'entity_widgets/controls/slider_controls.dart';
2018-10-27 14:27:41 +03:00
part 'entity_widgets/state/text_input_state.dart';
part 'entity_widgets/state/select_state.dart';
part 'entity_widgets/state/simple_state.dart';
part 'entity_widgets/state/climate_state.dart';
part 'entity_widgets/state/cover_state.dart';
part 'entity_widgets/state/date_time_state.dart';
part 'entity_widgets/state/button_state.dart';
2018-11-23 19:18:17 +02:00
part 'entity_widgets/state/lock_state.dart';
2018-10-27 14:27:41 +03:00
part 'entity_widgets/controls/climate_controls.dart';
part 'entity_widgets/controls/cover_controls.dart';
part 'entity_widgets/controls/light_controls.dart';
2018-11-17 22:40:33 +02:00
part 'entity_widgets/controls/media_player_widgets.dart';
2018-09-25 22:47:06 +03:00
part 'settings.page.dart';
part 'home_assistant.class.dart';
2018-09-25 22:47:06 +03:00
part 'log.page.dart';
2018-09-29 16:19:01 +03:00
part 'entity.page.dart';
2018-09-25 22:47:06 +03:00
part 'utils.class.dart';
part 'mdi.class.dart';
2018-09-26 22:16:50 +03:00
part 'entity_collection.class.dart';
2018-10-27 17:28:47 +03:00
part 'ui_class/ui.dart';
part 'ui_class/view.class.dart';
part 'ui_class/card.class.dart';
2018-11-12 20:28:10 +02:00
part 'ui_class/sizes_class.dart';
2018-10-27 17:28:47 +03:00
part 'ui_widgets/view.dart';
part 'ui_widgets/entities_card.dart';
2018-11-14 19:52:17 +02:00
part 'ui_widgets/glance_card.dart';
2018-10-27 17:28:47 +03:00
part 'ui_widgets/unsupported_card.dart';
part 'ui_widgets/media_control_card.dart';
part 'ui_widgets/card_header_widget.dart';
2018-09-10 00:34:52 +03:00
EventBus eventBus = new EventBus();
const String appName = "HA Client";
2018-11-24 01:20:18 +02:00
const appVersion = "0.3.9-72";
String homeAssistantWebHost;
void main() {
FlutterError.onError = (errorDetails) {
2018-10-27 01:24:23 +03:00
TheLogger.error( "${errorDetails.exception}");
if (TheLogger.isInDebugMode) {
FlutterError.dumpErrorToConsole(errorDetails);
}
};
runZoned(() {
2018-09-25 22:47:06 +03:00
runApp(new HAClientApp());
}, onError: (error, stack) {
2018-10-27 01:24:23 +03:00
TheLogger.error("$error");
TheLogger.error("$stack");
if (TheLogger.isInDebugMode) {
debugPrint("$stack");
}
});
}
2018-09-10 00:34:52 +03:00
2018-09-25 22:47:06 +03:00
class HAClientApp extends StatelessWidget {
2018-09-10 00:34:52 +03:00
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: appName,
2018-09-10 00:34:52 +03:00
theme: new ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: "/",
routes: {
2018-10-02 00:41:40 +03:00
"/": (context) => MainPage(title: 'HA Client'),
2018-10-27 00:54:05 +03:00
"/connection-settings": (context) => ConnectionSettingsPage(title: "Settings"),
"/log-view": (context) => LogViewPage(title: "Log")
},
2018-09-10 00:34:52 +03:00
);
}
}
class MainPage extends StatefulWidget {
MainPage({Key key, this.title}) : super(key: key);
2018-09-10 00:34:52 +03:00
final String title;
@override
_MainPageState createState() => new _MainPageState();
2018-09-10 00:34:52 +03:00
}
2018-09-16 19:24:26 +03:00
class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
HomeAssistant _homeAssistant;
//Map _instanceConfig;
2018-10-07 23:06:06 +03:00
String _webSocketApiEndpoint;
String _password;
String _authType;
2018-10-25 00:54:20 +03:00
//int _uiViewsCount = 0;
String _instanceHost;
StreamSubscription _stateSubscription;
2018-09-21 00:39:49 +03:00
StreamSubscription _settingsSubscription;
StreamSubscription _serviceCallSubscription;
2018-09-29 16:19:01 +03:00
StreamSubscription _showEntityPageSubscription;
2018-10-07 02:17:14 +03:00
StreamSubscription _refreshDataSubscription;
StreamSubscription _showErrorSubscription;
2018-11-18 12:46:54 +02:00
bool _settingsLoaded = false;
bool _accountMenuExpanded = false;
2018-10-27 00:54:05 +03:00
bool _useLovelaceUI;
@override
void initState() {
super.initState();
2018-11-18 12:46:54 +02:00
_settingsLoaded = false;
2018-09-16 19:24:26 +03:00
WidgetsBinding.instance.addObserver(this);
2018-11-18 13:19:00 +02:00
TheLogger.debug("<!!!> Creating new HomeAssistant instance");
_homeAssistant = HomeAssistant();
2018-09-21 00:39:49 +03:00
_settingsSubscription = eventBus.on<SettingsChangedEvent>().listen((event) {
2018-10-27 01:24:23 +03:00
TheLogger.debug("Settings change event: reconnect=${event.reconnect}");
if (event.reconnect) {
_homeAssistant.disconnect().then((_){
_initialLoad();
});
}
});
_initialLoad();
}
void _initialLoad() {
_loadConnectionSettings().then((_){
_subscribe();
_refreshData();
}, onError: (_) {
2018-11-18 12:46:54 +02:00
_showErrorBottomBar(message: _, errorCode: 5);
});
}
2018-09-10 00:34:52 +03:00
2018-09-16 19:24:26 +03:00
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
2018-10-27 01:24:23 +03:00
TheLogger.debug("$state");
2018-11-18 12:46:54 +02:00
if (state == AppLifecycleState.resumed && _settingsLoaded) {
2018-09-16 19:24:26 +03:00
_refreshData();
2018-11-18 12:46:54 +02:00
}
2018-09-16 19:24:26 +03:00
}
_loadConnectionSettings() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String domain = prefs.getString('hassio-domain');
String port = prefs.getString('hassio-port');
2018-09-17 22:20:36 +03:00
_instanceHost = "$domain:$port";
2018-10-07 23:06:06 +03:00
_webSocketApiEndpoint = "${prefs.getString('hassio-protocol')}://$domain:$port/api/websocket";
homeAssistantWebHost = "${prefs.getString('hassio-res-protocol')}://$domain:$port";
2018-10-07 23:06:06 +03:00
_password = prefs.getString('hassio-password');
_authType = prefs.getString('hassio-auth-type');
2018-10-27 00:54:05 +03:00
_useLovelaceUI = prefs.getBool('use-lovelace') ?? false;
2018-10-07 23:06:06 +03:00
if ((domain == null) || (port == null) || (_password == null) ||
(domain.length == 0) || (port.length == 0) || (_password.length == 0)) {
throw("Check connection settings");
2018-11-18 12:46:54 +02:00
} else {
2018-10-03 15:25:01 +03:00
_settingsLoaded = true;
2018-11-18 12:46:54 +02:00
}
}
_subscribe() {
if (_stateSubscription == null) {
_stateSubscription = eventBus.on<StateChangedEvent>().listen((event) {
setState(() {});
});
}
if (_serviceCallSubscription == null) {
_serviceCallSubscription =
eventBus.on<ServiceCallEvent>().listen((event) {
_callService(event.domain, event.service, event.entityId,
event.additionalParams);
});
}
2018-09-29 16:19:01 +03:00
if (_showEntityPageSubscription == null) {
_showEntityPageSubscription =
eventBus.on<ShowEntityPageEvent>().listen((event) {
2018-11-18 13:19:00 +02:00
_showEntityPage(event.entity.entityId);
});
}
2018-10-07 02:17:14 +03:00
if (_refreshDataSubscription == null) {
_refreshDataSubscription = eventBus.on<RefreshDataEvent>().listen((event){
_refreshData();
});
}
if (_showErrorSubscription == null) {
_showErrorSubscription = eventBus.on<ShowErrorEvent>().listen((event){
2018-11-18 12:46:54 +02:00
_showErrorBottomBar(message: event.text, errorCode: event.errorCode);
});
}
}
_refreshData() async {
2018-10-27 00:54:05 +03:00
_homeAssistant.updateSettings(_webSocketApiEndpoint, _password, _authType, _useLovelaceUI);
2018-11-18 12:46:54 +02:00
_hideBottomBar();
_showInfoBottomBar(progress: true,);
await _homeAssistant.fetch().then((result) {
2018-11-18 12:46:54 +02:00
_hideBottomBar();
}).catchError((e) {
_setErrorState(e);
});
2018-10-07 02:17:14 +03:00
eventBus.fire(RefreshDataFinishedEvent());
2018-09-11 01:09:21 +03:00
}
_setErrorState(e) {
2018-11-04 18:20:06 +02:00
if (e is Error) {
TheLogger.error(e.toString());
TheLogger.error("${e.stackTrace}");
2018-11-18 12:46:54 +02:00
_showErrorBottomBar(
2018-11-04 18:20:06 +02:00
message: "There was some error",
errorCode: 13
);
} else {
2018-11-18 12:46:54 +02:00
_showErrorBottomBar(
2018-11-04 18:20:06 +02:00
message: e != null ? e["errorMessage"] ?? "$e" : "Unknown error",
errorCode: e["errorCode"] != null ? e["errorCode"] : 99
);
}
}
2018-10-16 17:35:13 +03:00
void _callService(String domain, String service, String entityId, Map<String, dynamic> additionalParams) {
2018-11-23 16:38:26 +02:00
_showInfoBottomBar(
message: "Calling $domain.$service",
duration: Duration(seconds: 3)
);
_homeAssistant.callService(domain, service, entityId, additionalParams).catchError((e) => _setErrorState(e));
}
2018-11-18 13:19:00 +02:00
void _showEntityPage(String entityId) {
2018-09-29 16:19:01 +03:00
Navigator.push(
context,
MaterialPageRoute(
2018-11-18 13:19:00 +02:00
builder: (context) => EntityViewPage(entityId: entityId, homeAssistant: _homeAssistant),
2018-09-29 16:19:01 +03:00
)
);
}
2018-10-07 02:17:14 +03:00
List<Tab> buildUIViewTabs() {
List<Tab> result = [];
2018-10-27 00:54:05 +03:00
if (_homeAssistant.ui.views.isNotEmpty) {
_homeAssistant.ui.views.forEach((HAView view) {
2018-11-04 22:19:45 +02:00
result.add(view.buildTab());
2018-10-27 00:54:05 +03:00
});
}
return result;
}
Drawer _buildAppDrawer() {
List<Widget> menuItems = [];
menuItems.add(
UserAccountsDrawerHeader(
accountName: Text(_homeAssistant.userName),
accountEmail: Text(_instanceHost ?? "Not configured"),
onDetailsPressed: () {
setState(() {
_accountMenuExpanded = !_accountMenuExpanded;
});
},
currentAccountPicture: CircleAvatar(
child: Text(
2018-10-08 23:11:56 +03:00
_homeAssistant.userAvatarText,
style: TextStyle(
fontSize: 32.0
),
),
),
)
);
if (_accountMenuExpanded) {
menuItems.addAll([
ListTile(
leading: Icon(Icons.settings),
2018-10-27 00:54:05 +03:00
title: Text("Settings"),
onTap: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed('/connection-settings');
},
),
Divider(),
]);
} else {
menuItems.addAll([
new ListTile(
leading: Icon(Icons.insert_drive_file),
title: Text("Log"),
onTap: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed('/log-view');
},
),
new ListTile(
leading: Icon(MaterialDesignIcons.createIconDataFromIconName("mdi:github-circle")),
title: Text("Report an issue"),
onTap: () {
Navigator.of(context).pop();
2018-11-17 22:55:04 +02:00
HAUtils.launchURL("https://github.com/estevez-dev/ha_client/issues/new");
},
),
Divider(),
new AboutListTile(
2018-11-17 23:02:05 +02:00
aboutBoxChildren: <Widget>[
GestureDetector(
onTap: () {
Navigator.of(context).pop();
HAUtils.launchURL("http://www.keyboardcrumbs.io/");
},
child: Text(
"www.keyboardcrumbs.io",
style: TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline
),
),
)
],
applicationName: appName,
applicationVersion: appVersion,
2018-11-17 23:02:05 +02:00
applicationLegalese: "Keyboard Crumbs",
)
]);
}
return new Drawer(
child: ListView(
children: menuItems,
),
);
}
2018-11-18 12:46:54 +02:00
void _hideBottomBar() {
//_scaffoldKey?.currentState?.hideCurrentSnackBar();
setState(() {
_showBottomBar = false;
});
2018-10-07 12:14:48 +03:00
}
2018-11-18 12:46:54 +02:00
Widget _bottomBarAction;
bool _showBottomBar = false;
String _bottomBarText;
bool _bottomBarProgress;
2018-11-18 12:46:54 +02:00
Color _bottomBarColor;
2018-11-23 16:38:26 +02:00
Timer _bottomBarTimer;
2018-11-18 12:46:54 +02:00
2018-11-23 16:38:26 +02:00
void _showInfoBottomBar({String message, bool progress: false, Duration duration}) {
_bottomBarTimer?.cancel();
2018-11-18 12:46:54 +02:00
_bottomBarAction = Container(height: 0.0, width: 0.0,);
2018-11-18 13:19:00 +02:00
_bottomBarColor = Colors.grey.shade50;
2018-11-18 12:46:54 +02:00
setState(() {
_bottomBarText = message;
_bottomBarProgress = progress;
2018-11-18 12:46:54 +02:00
_showBottomBar = true;
});
2018-11-23 16:38:26 +02:00
if (duration != null) {
_bottomBarTimer = Timer(duration, () {
_hideBottomBar();
});
}
2018-11-18 12:46:54 +02:00
}
void _showErrorBottomBar({Key key, @required String message, @required int errorCode}) {
TextStyle textStyle = TextStyle(
color: Colors.blue,
fontSize: Sizes.nameFontSize
);
_bottomBarColor = Colors.red.shade100;
switch (errorCode) {
case 9:
case 11:
case 7:
case 1: {
2018-11-18 12:46:54 +02:00
_bottomBarAction = FlatButton(
child: Text("Retry", style: textStyle),
onPressed: () {
2018-11-18 12:46:54 +02:00
//_scaffoldKey?.currentState?.hideCurrentSnackBar();
_refreshData();
},
);
break;
}
case 5: {
message = "Check connection settings";
2018-11-18 12:46:54 +02:00
_bottomBarAction = FlatButton(
child: Text("Open", style: textStyle),
onPressed: () {
2018-11-18 12:46:54 +02:00
//_scaffoldKey?.currentState?.hideCurrentSnackBar();
Navigator.pushNamed(context, '/connection-settings');
},
);
break;
}
case 6: {
2018-11-18 12:46:54 +02:00
_bottomBarAction = FlatButton(
child: Text("Settings", style: textStyle),
onPressed: () {
2018-11-18 12:46:54 +02:00
//_scaffoldKey?.currentState?.hideCurrentSnackBar();
Navigator.pushNamed(context, '/connection-settings');
},
);
break;
}
case 10: {
2018-11-18 12:46:54 +02:00
_bottomBarAction = FlatButton(
child: Text("Refresh", style: textStyle),
onPressed: () {
2018-11-18 12:46:54 +02:00
//_scaffoldKey?.currentState?.hideCurrentSnackBar();
_refreshData();
},
);
break;
}
case 8: {
2018-11-18 12:46:54 +02:00
_bottomBarAction = FlatButton(
child: Text("Reconnect", style: textStyle),
onPressed: () {
2018-11-18 12:46:54 +02:00
//_scaffoldKey?.currentState?.hideCurrentSnackBar();
_refreshData();
},
);
break;
}
2018-11-04 18:20:06 +02:00
default: {
2018-11-18 12:46:54 +02:00
_bottomBarAction = FlatButton(
child: Text("Reload", style: textStyle),
2018-11-04 18:20:06 +02:00
onPressed: () {
2018-11-18 12:46:54 +02:00
//_scaffoldKey?.currentState?.hideCurrentSnackBar();
2018-11-04 18:20:06 +02:00
_refreshData();
},
);
break;
}
}
2018-11-18 12:46:54 +02:00
setState(() {
_bottomBarProgress = false;
2018-11-18 12:46:54 +02:00
_bottomBarText = "$message (code: $errorCode)";
_showBottomBar = true;
});
/*_scaffoldKey.currentState.hideCurrentSnackBar();
_scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Text("$message (code: $errorCode)"),
action: action,
duration: Duration(hours: 1),
)
2018-11-18 12:46:54 +02:00
);*/
}
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
2018-11-14 18:03:50 +02:00
Widget _buildScaffoldBody(bool empty) {
return NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
floating: true,
pinned: true,
primary: true,
2018-11-18 12:46:54 +02:00
title: Text(_homeAssistant != null ? _homeAssistant.locationName : ""),
2018-11-14 18:03:50 +02:00
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: () {
_scaffoldKey.currentState.openDrawer();
setState(() {
_accountMenuExpanded = false;
});
},
),
bottom: empty ? null : TabBar(
tabs: buildUIViewTabs(),
isScrollable: true,
),
2018-09-24 22:54:51 +03:00
),
2018-11-14 18:03:50 +02:00
];
},
body: empty ?
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
MaterialDesignIcons.createIconDataFromIconName("mdi:home-assistant"),
size: 100.0,
2018-11-18 12:46:54 +02:00
color: Colors.blue,
2018-11-14 18:03:50 +02:00
),
]
),
)
:
_homeAssistant.buildViews(context, _useLovelaceUI),
2018-09-24 22:54:51 +03:00
);
}
2018-09-10 00:34:52 +03:00
@override
Widget build(BuildContext context) {
2018-11-18 12:46:54 +02:00
Widget bottomBar;
if (_showBottomBar) {
List<Widget> bottomBarChildren = [];
if (_bottomBarText != null) {
bottomBarChildren.add(
Padding(
padding: EdgeInsets.fromLTRB(
Sizes.leftWidgetPadding, Sizes.rowPadding, 0.0,
Sizes.rowPadding),
child: Text(
"$_bottomBarText",
textAlign: TextAlign.left,
softWrap: true,
),
)
);
}
if (_bottomBarProgress) {
bottomBarChildren.add(
CollectionScaleTransition(
children: <Widget>[
Icon(Icons.stop, size: 10.0, color: EntityColor.stateColor(EntityState.on),),
Icon(Icons.stop, size: 10.0, color: EntityColor.stateColor(EntityState.unavailable),),
Icon(Icons.stop, size: 10.0, color: EntityColor.stateColor(EntityState.off),),
],
),
);
}
if (bottomBarChildren.isNotEmpty) {
bottomBar = Container(
color: _bottomBarColor,
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: Column(
crossAxisAlignment: _bottomBarProgress ? CrossAxisAlignment.center : CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: bottomBarChildren,
2018-11-18 12:46:54 +02:00
),
),
_bottomBarAction
],
),
);
}
2018-11-18 12:46:54 +02:00
}
// This method is rerun every time setState is called.
2018-11-04 11:23:21 +02:00
if (_homeAssistant.ui == null || _homeAssistant.ui.views == null) {
2018-11-14 18:03:50 +02:00
return Scaffold(
key: _scaffoldKey,
2018-11-16 14:30:43 +02:00
primary: false,
2018-11-14 18:03:50 +02:00
drawer: _buildAppDrawer(),
2018-11-18 12:46:54 +02:00
bottomNavigationBar: bottomBar,
2018-11-14 18:03:50 +02:00
body: _buildScaffoldBody(true)
);
} else {
2018-11-14 18:03:50 +02:00
return Scaffold(
key: _scaffoldKey,
drawer: _buildAppDrawer(),
2018-11-16 14:30:43 +02:00
primary: false,
2018-11-18 12:46:54 +02:00
bottomNavigationBar: bottomBar,
2018-11-14 18:03:50 +02:00
body: DefaultTabController(
length: _homeAssistant.ui?.views?.length ?? 0,
child: _buildScaffoldBody(false),
),
);
}
2018-09-10 00:34:52 +03:00
}
@override
void dispose() {
2018-09-16 19:24:26 +03:00
WidgetsBinding.instance.removeObserver(this);
if (_stateSubscription != null) _stateSubscription.cancel();
2018-09-21 00:39:49 +03:00
if (_settingsSubscription != null) _settingsSubscription.cancel();
if (_serviceCallSubscription != null) _serviceCallSubscription.cancel();
2018-09-29 16:19:01 +03:00
if (_showEntityPageSubscription != null) _showEntityPageSubscription.cancel();
2018-10-07 02:17:14 +03:00
if (_refreshDataSubscription != null) _refreshDataSubscription.cancel();
if (_showErrorSubscription != null) _showErrorSubscription.cancel();
_homeAssistant.disconnect();
super.dispose();
}
2018-09-10 00:34:52 +03:00
}