2018-09-10 00:34:52 +03:00
|
|
|
import 'dart:convert';
|
2018-09-15 01:46:15 +03:00
|
|
|
import 'dart:async';
|
2019-01-31 01:04:13 +02:00
|
|
|
import 'dart:typed_data';
|
2018-09-15 12:56:42 +03:00
|
|
|
import 'package:flutter/rendering.dart';
|
2018-09-10 00:34:52 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2018-09-10 03:06:35 +03:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2018-09-12 00:32:04 +03:00
|
|
|
import 'package:web_socket_channel/io.dart';
|
2018-09-16 18:02:12 +03:00
|
|
|
import 'package:event_bus/event_bus.dart';
|
2018-09-16 19:24:26 +03:00
|
|
|
import 'package:flutter/widgets.dart';
|
2018-09-23 02:04:44 +03:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2019-03-13 17:05:15 +02:00
|
|
|
import 'package:url_launcher/url_launcher.dart' as urlLauncher;
|
2018-09-25 22:11:31 +03:00
|
|
|
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-28 14:56:23 +02:00
|
|
|
import 'package:charts_flutter/flutter.dart' as charts;
|
2018-11-23 16:30:42 +02:00
|
|
|
import 'package:progress_indicators/progress_indicators.dart';
|
2019-01-23 23:34:45 +02:00
|
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
2019-02-20 17:55:56 +02:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
2019-03-13 17:05:15 +02:00
|
|
|
import 'package:flutter_custom_tabs/flutter_custom_tabs.dart';
|
2019-03-18 23:37:45 +02:00
|
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
2019-03-19 23:07:40 +02:00
|
|
|
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
|
2019-03-21 14:25:05 +02:00
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
2019-03-30 00:29:52 +02:00
|
|
|
import 'package:device_info/device_info.dart';
|
2018-09-10 03:06:35 +03:00
|
|
|
|
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';
|
2019-03-13 21:33:58 +02:00
|
|
|
part 'entity_class/timer_entity.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-24 11:33:59 +02:00
|
|
|
part 'entity_class/group_entity.class.dart';
|
2018-11-24 17:00:45 +02:00
|
|
|
part 'entity_class/fan_entity.class.dart';
|
2019-01-25 23:48:31 +02:00
|
|
|
part 'entity_class/automation_entity.dart';
|
2019-01-29 21:59:05 +02:00
|
|
|
part 'entity_class/camera_entity.class.dart';
|
2019-01-28 16:48:49 +02:00
|
|
|
part 'entity_class/alarm_control_panel.class.dart';
|
2018-11-17 22:40:33 +02:00
|
|
|
part 'entity_widgets/common/badge.dart';
|
2018-10-28 14:56:23 +02:00
|
|
|
part 'entity_widgets/model_widgets.dart';
|
2018-10-27 14:27:41 +03:00
|
|
|
part 'entity_widgets/default_entity_container.dart';
|
2019-03-12 23:35:33 +02:00
|
|
|
part 'entity_widgets/missed_entity.dart';
|
2018-11-14 19:52:17 +02:00
|
|
|
part 'entity_widgets/glance_entity_container.dart';
|
2018-11-25 20:44:19 +02:00
|
|
|
part 'entity_widgets/button_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';
|
2019-01-25 23:48:31 +02:00
|
|
|
part 'entity_widgets/common/flat_service_button.dart';
|
2019-02-10 17:15:52 +02:00
|
|
|
part 'entity_widgets/common/light_color_picker.dart';
|
2019-02-20 16:39:57 +02:00
|
|
|
part 'entity_widgets/common/camera_stream_view.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';
|
2018-10-29 00:58:52 +02:00
|
|
|
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';
|
2019-03-13 21:33:58 +02:00
|
|
|
part 'entity_widgets/state/timer_state.dart';
|
2018-10-27 14:27:41 +03:00
|
|
|
part 'entity_widgets/state/climate_state.dart';
|
|
|
|
part 'entity_widgets/state/cover_state.dart';
|
|
|
|
part 'entity_widgets/state/date_time_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-11-24 17:00:45 +02:00
|
|
|
part 'entity_widgets/controls/fan_controls.dart';
|
2019-01-30 00:25:41 +02:00
|
|
|
part 'entity_widgets/controls/alarm_control_panel_controls.dart';
|
2018-09-25 22:47:06 +03:00
|
|
|
part 'settings.page.dart';
|
2019-03-13 16:39:23 +02:00
|
|
|
part 'panel.page.dart';
|
2018-09-27 14:51:57 +03:00
|
|
|
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';
|
2019-03-26 00:18:30 +02:00
|
|
|
part 'auth_manager.class.dart';
|
|
|
|
part 'connection.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';
|
2019-03-13 16:39:23 +02:00
|
|
|
part 'ui_class/panel_class.dart';
|
2018-10-27 17:28:47 +03:00
|
|
|
part 'ui_widgets/view.dart';
|
2018-12-07 22:04:14 +02:00
|
|
|
part 'ui_widgets/card_widget.dart';
|
2018-10-30 22:51:45 +02:00
|
|
|
part 'ui_widgets/card_header_widget.dart';
|
2019-03-13 16:39:23 +02:00
|
|
|
part 'ui_widgets/config_panel_widget.dart';
|
2018-10-30 22:51:45 +02:00
|
|
|
|
2018-09-10 00:34:52 +03:00
|
|
|
|
2018-09-16 18:02:12 +03:00
|
|
|
EventBus eventBus = new EventBus();
|
2019-03-30 00:29:52 +02:00
|
|
|
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
|
2018-09-18 23:21:05 +03:00
|
|
|
const String appName = "HA Client";
|
2019-04-04 22:12:08 +03:00
|
|
|
const appVersion = "0.6.0-alpha2";
|
2018-09-16 18:02:12 +03:00
|
|
|
|
2018-09-24 20:07:22 +03:00
|
|
|
void main() {
|
|
|
|
FlutterError.onError = (errorDetails) {
|
2018-12-15 14:09:37 +02:00
|
|
|
Logger.e( "${errorDetails.exception}");
|
|
|
|
if (Logger.isInDebugMode) {
|
2018-09-24 20:07:22 +03:00
|
|
|
FlutterError.dumpErrorToConsole(errorDetails);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
runZoned(() {
|
2018-09-25 22:47:06 +03:00
|
|
|
runApp(new HAClientApp());
|
2018-09-24 20:07:22 +03:00
|
|
|
}, onError: (error, stack) {
|
2018-12-15 14:09:37 +02:00
|
|
|
Logger.e("$error");
|
|
|
|
Logger.e("$stack");
|
|
|
|
if (Logger.isInDebugMode) {
|
2018-09-27 14:51:57 +03:00
|
|
|
debugPrint("$stack");
|
|
|
|
}
|
2018-09-24 20:07:22 +03:00
|
|
|
});
|
|
|
|
}
|
2018-09-10 00:34:52 +03:00
|
|
|
|
2018-09-25 22:47:06 +03:00
|
|
|
class HAClientApp extends StatelessWidget {
|
2019-03-20 12:48:00 +02:00
|
|
|
|
|
|
|
final HomeAssistant homeAssistant = HomeAssistant();
|
2018-09-10 00:34:52 +03:00
|
|
|
// This widget is the root of your application.
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return new MaterialApp(
|
2018-09-17 01:03:34 +03:00
|
|
|
title: appName,
|
2018-09-10 00:34:52 +03:00
|
|
|
theme: new ThemeData(
|
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
),
|
2018-09-10 03:06:35 +03:00
|
|
|
initialRoute: "/",
|
|
|
|
routes: {
|
2019-03-20 12:48:00 +02:00
|
|
|
"/": (context) => MainPage(title: 'HA Client', homeAssistant: homeAssistant,),
|
2018-10-27 00:54:05 +03:00
|
|
|
"/connection-settings": (context) => ConnectionSettingsPage(title: "Settings"),
|
2019-03-13 16:39:23 +02:00
|
|
|
"/configuration": (context) => PanelPage(title: "Configuration"),
|
2018-09-24 00:05:57 +03:00
|
|
|
"/log-view": (context) => LogViewPage(title: "Log")
|
2018-09-10 03:06:35 +03:00
|
|
|
},
|
2018-09-10 00:34:52 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-10 03:06:35 +03:00
|
|
|
class MainPage extends StatefulWidget {
|
2019-03-20 12:48:00 +02:00
|
|
|
MainPage({Key key, this.title, this.homeAssistant}) : super(key: key);
|
2018-09-10 00:34:52 +03:00
|
|
|
|
|
|
|
final String title;
|
2019-03-20 12:48:00 +02:00
|
|
|
final HomeAssistant homeAssistant;
|
2018-09-10 00:34:52 +03:00
|
|
|
|
|
|
|
@override
|
2018-09-10 03:06:35 +03:00
|
|
|
_MainPageState createState() => new _MainPageState();
|
2018-09-10 00:34:52 +03:00
|
|
|
}
|
|
|
|
|
2019-02-21 15:35:58 +02:00
|
|
|
class _MainPageState extends State<MainPage> with WidgetsBindingObserver, TickerProviderStateMixin {
|
2019-03-20 23:05:25 +02:00
|
|
|
|
2018-11-16 22:32:43 +02:00
|
|
|
StreamSubscription _stateSubscription;
|
2018-09-21 00:39:49 +03:00
|
|
|
StreamSubscription _settingsSubscription;
|
2018-09-29 13:49:25 +03:00
|
|
|
StreamSubscription _serviceCallSubscription;
|
2018-09-29 16:19:01 +03:00
|
|
|
StreamSubscription _showEntityPageSubscription;
|
2018-10-07 10:28:28 +03:00
|
|
|
StreamSubscription _showErrorSubscription;
|
2019-03-20 19:01:30 +02:00
|
|
|
StreamSubscription _startAuthSubscription;
|
|
|
|
StreamSubscription _reloadUISubscription;
|
2019-02-22 15:28:11 +02:00
|
|
|
int _previousViewCount;
|
2019-04-05 13:39:54 +03:00
|
|
|
bool _showLoginButton = false;
|
2018-09-29 13:49:25 +03:00
|
|
|
|
2018-09-10 03:06:35 +03:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2019-03-19 23:07:40 +02:00
|
|
|
WidgetsBinding.instance.addObserver(this);
|
2018-10-03 14:36:23 +03:00
|
|
|
|
2019-03-29 13:09:34 +02:00
|
|
|
_firebaseMessaging.configure(
|
|
|
|
onLaunch: (data) {
|
|
|
|
Logger.d("Notification [onLaunch]: $data");
|
|
|
|
},
|
|
|
|
onMessage: (data) {
|
|
|
|
Logger.d("Notification [onMessage]: $data");
|
|
|
|
},
|
|
|
|
onResume: (data) {
|
|
|
|
Logger.d("Notification [onResume]: $data");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-09-21 00:39:49 +03:00
|
|
|
_settingsSubscription = eventBus.on<SettingsChangedEvent>().listen((event) {
|
2018-12-15 14:09:37 +02:00
|
|
|
Logger.d("Settings change event: reconnect=${event.reconnect}");
|
2018-10-03 14:36:23 +03:00
|
|
|
if (event.reconnect) {
|
2019-04-05 11:48:41 +03:00
|
|
|
_fullLoad();
|
2018-10-03 14:36:23 +03:00
|
|
|
}
|
|
|
|
});
|
2019-03-18 23:37:45 +02:00
|
|
|
|
2019-04-05 11:48:41 +03:00
|
|
|
_fullLoad();
|
2018-10-07 17:07:06 +03:00
|
|
|
}
|
|
|
|
|
2019-04-05 11:48:41 +03:00
|
|
|
void _fullLoad() async {
|
2019-03-26 00:18:30 +02:00
|
|
|
_showInfoBottomBar(progress: true,);
|
2019-04-05 11:48:41 +03:00
|
|
|
_subscribe().then((_) {
|
|
|
|
Connection().init(loadSettings: true, forceReconnect: true).then((__){
|
|
|
|
_fetchData();
|
2019-04-05 12:08:32 +03:00
|
|
|
}, onError: (e) {
|
|
|
|
_setErrorState(e);
|
2019-04-05 11:48:41 +03:00
|
|
|
});
|
2018-09-20 23:21:03 +03:00
|
|
|
});
|
2018-09-10 03:06:35 +03:00
|
|
|
}
|
2018-09-10 00:34:52 +03:00
|
|
|
|
2019-04-05 11:48:41 +03:00
|
|
|
void _quickLoad() {
|
2019-03-26 00:18:30 +02:00
|
|
|
_hideBottomBar();
|
|
|
|
_showInfoBottomBar(progress: true,);
|
2019-04-05 11:48:41 +03:00
|
|
|
Connection().init(loadSettings: false, forceReconnect: false).then((_){
|
2019-03-26 00:18:30 +02:00
|
|
|
_fetchData();
|
|
|
|
}, onError: (e) {
|
|
|
|
_setErrorState(e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_fetchData() async {
|
2019-04-05 11:48:41 +03:00
|
|
|
await widget.homeAssistant.fetchData().then((_) {
|
2019-03-26 00:18:30 +02:00
|
|
|
_hideBottomBar();
|
|
|
|
int currentViewCount = widget.homeAssistant.ui?.views?.length ?? 0;
|
|
|
|
if (_previousViewCount != currentViewCount) {
|
|
|
|
Logger.d("Views count changed ($_previousViewCount->$currentViewCount). Creating new tabs controller.");
|
|
|
|
_viewsTabController = TabController(vsync: this, length: currentViewCount);
|
|
|
|
_previousViewCount = currentViewCount;
|
|
|
|
}
|
|
|
|
}).catchError((e) {
|
|
|
|
_setErrorState(e);
|
|
|
|
});
|
|
|
|
eventBus.fire(RefreshDataFinishedEvent());
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:24:26 +03:00
|
|
|
@override
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
2019-03-26 00:18:30 +02:00
|
|
|
Logger.d("$state");
|
2019-04-05 11:48:41 +03:00
|
|
|
if (state == AppLifecycleState.resumed && Connection().settingsLoaded) {
|
|
|
|
_quickLoad();
|
2018-11-18 12:46:54 +02:00
|
|
|
}
|
2018-09-16 19:24:26 +03:00
|
|
|
}
|
|
|
|
|
2019-03-29 13:09:34 +02:00
|
|
|
Future _subscribe() {
|
|
|
|
Completer completer = Completer();
|
2018-11-16 22:32:43 +02:00
|
|
|
if (_stateSubscription == null) {
|
|
|
|
_stateSubscription = eventBus.on<StateChangedEvent>().listen((event) {
|
2018-12-15 14:09:37 +02:00
|
|
|
if (event.needToRebuildUI) {
|
|
|
|
Logger.d("New entity. Need to rebuild UI");
|
2019-04-05 11:48:41 +03:00
|
|
|
_quickLoad();
|
2018-12-15 14:09:37 +02:00
|
|
|
} else {
|
|
|
|
setState(() {});
|
|
|
|
}
|
2018-11-16 22:32:43 +02:00
|
|
|
});
|
|
|
|
}
|
2019-03-20 19:01:30 +02:00
|
|
|
if (_reloadUISubscription == null) {
|
|
|
|
_reloadUISubscription = eventBus.on<ReloadUIEvent>().listen((event){
|
2019-04-05 11:48:41 +03:00
|
|
|
_quickLoad();
|
2019-03-20 19:01:30 +02:00
|
|
|
});
|
|
|
|
}
|
2018-10-03 14:36:23 +03:00
|
|
|
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
|
|
|
|
2018-10-03 14:36:23 +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-03 14:36:23 +03:00
|
|
|
});
|
|
|
|
}
|
2018-10-07 02:17:14 +03:00
|
|
|
|
2018-10-07 10:28:28 +03:00
|
|
|
if (_showErrorSubscription == null) {
|
|
|
|
_showErrorSubscription = eventBus.on<ShowErrorEvent>().listen((event){
|
2019-04-19 21:43:52 +03:00
|
|
|
_showErrorBottomBar(event.error);
|
2018-10-07 10:28:28 +03:00
|
|
|
});
|
|
|
|
}
|
2019-03-18 23:37:45 +02:00
|
|
|
|
2019-03-20 19:01:30 +02:00
|
|
|
if (_startAuthSubscription == null) {
|
|
|
|
_startAuthSubscription = eventBus.on<StartAuthEvent>().listen((event){
|
2019-04-05 13:39:54 +03:00
|
|
|
setState(() {
|
2019-04-05 14:07:03 +03:00
|
|
|
_showLoginButton = event.showButton;
|
2019-04-05 13:39:54 +03:00
|
|
|
});
|
2019-03-20 19:01:30 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-29 13:09:34 +02:00
|
|
|
_firebaseMessaging.getToken().then((String token) {
|
2019-03-30 00:29:52 +02:00
|
|
|
Logger.d("Device name: ${json.encode(Connection().deviceName)}");
|
2019-04-05 13:06:14 +03:00
|
|
|
Connection().sendHTTPPost(
|
2019-03-30 00:29:52 +02:00
|
|
|
endPoint: '/api/notify.ha-client',
|
|
|
|
data: '{"token": "$token", "device": ${json.encode(Connection().deviceName)}}'
|
2019-03-29 13:09:34 +02:00
|
|
|
).then((_) {
|
|
|
|
Logger.d("Notificatin listener registered.");
|
|
|
|
completer.complete();
|
2019-03-30 00:29:52 +02:00
|
|
|
}).catchError((e) {
|
|
|
|
Logger.e("Error registering notification listener: ${e.toString()}");
|
|
|
|
completer.complete();
|
2019-03-29 13:09:34 +02:00
|
|
|
});
|
|
|
|
}).catchError((e) {
|
|
|
|
Logger.e("Error registering notification listener: ${e.toString()}");
|
|
|
|
completer.complete();
|
2019-03-18 23:37:45 +02:00
|
|
|
});
|
2019-03-29 13:09:34 +02:00
|
|
|
return completer.future;
|
2018-09-12 00:32:04 +03:00
|
|
|
}
|
|
|
|
|
2019-03-20 23:05:25 +02:00
|
|
|
void _showOAuth() {
|
2019-06-15 14:36:11 +03:00
|
|
|
Logger.d("_showOAuth: ${Connection().oauthUrl}");
|
2019-03-20 23:05:25 +02:00
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => WebviewScaffold(
|
2019-04-05 13:06:14 +03:00
|
|
|
url: "${Connection().oauthUrl}",
|
2019-03-20 23:05:25 +02:00
|
|
|
appBar: new AppBar(
|
2019-03-26 00:18:30 +02:00
|
|
|
leading: IconButton(
|
|
|
|
icon: Icon(Icons.help),
|
|
|
|
onPressed: () => HAUtils.launchURLInCustomTab(context, "http://ha-client.homemade.systems/docs#authentication")
|
|
|
|
),
|
|
|
|
title: new Text("Login to your Home Assistant"),
|
2019-03-20 23:05:25 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-19 21:43:52 +03:00
|
|
|
_setErrorState(HAError e) {
|
|
|
|
if (e == null) {
|
2018-11-18 12:46:54 +02:00
|
|
|
_showErrorBottomBar(
|
2019-04-19 21:43:52 +03:00
|
|
|
HAError("Unknown error")
|
2018-11-04 18:20:06 +02:00
|
|
|
);
|
|
|
|
} else {
|
2019-04-19 21:43:52 +03:00
|
|
|
_showErrorBottomBar(e);
|
2018-11-04 18:20:06 +02:00
|
|
|
}
|
2018-09-21 00:01:53 +03:00
|
|
|
}
|
|
|
|
|
2019-03-26 00:18:30 +02:00
|
|
|
void _callService(String domain, String service, String entityId, Map additionalParams) {
|
2018-11-23 16:38:26 +02:00
|
|
|
_showInfoBottomBar(
|
|
|
|
message: "Calling $domain.$service",
|
|
|
|
duration: Duration(seconds: 3)
|
|
|
|
);
|
2019-04-05 13:06:14 +03:00
|
|
|
Connection().callService(domain: domain, service: service, entityId: entityId, additionalServiceData: additionalParams).catchError((e) => _setErrorState(e));
|
2018-09-21 00:01:53 +03:00
|
|
|
}
|
|
|
|
|
2018-11-18 13:19:00 +02:00
|
|
|
void _showEntityPage(String entityId) {
|
2018-09-29 16:19:01 +03:00
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
2019-03-20 12:48:00 +02:00
|
|
|
builder: (context) => EntityViewPage(entityId: entityId, homeAssistant: widget.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
|
|
|
|
2019-03-20 12:48:00 +02:00
|
|
|
if (widget.homeAssistant.ui.views.isNotEmpty) {
|
|
|
|
widget.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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-16 14:58:21 +03:00
|
|
|
return result;
|
2018-09-15 01:46:15 +03:00
|
|
|
}
|
|
|
|
|
2018-09-16 14:58:21 +03:00
|
|
|
Drawer _buildAppDrawer() {
|
2018-10-07 20:18:14 +03:00
|
|
|
List<Widget> menuItems = [];
|
|
|
|
menuItems.add(
|
|
|
|
UserAccountsDrawerHeader(
|
2019-03-20 12:48:00 +02:00
|
|
|
accountName: Text(widget.homeAssistant.userName),
|
2019-04-05 11:57:58 +03:00
|
|
|
accountEmail: Text(Connection().displayHostname ?? "Not configured"),
|
2019-03-20 23:38:57 +02:00
|
|
|
/*onDetailsPressed: () {
|
2018-10-07 20:18:14 +03:00
|
|
|
setState(() {
|
|
|
|
_accountMenuExpanded = !_accountMenuExpanded;
|
|
|
|
});
|
2019-03-20 23:38:57 +02:00
|
|
|
},*/
|
2018-10-07 20:18:14 +03:00
|
|
|
currentAccountPicture: CircleAvatar(
|
|
|
|
child: Text(
|
2019-03-20 12:48:00 +02:00
|
|
|
widget.homeAssistant.userAvatarText,
|
2018-10-07 20:18:14 +03:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 32.0
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
2019-03-21 14:08:07 +02:00
|
|
|
if (widget.homeAssistant.panels.isNotEmpty) {
|
2019-03-20 12:48:00 +02:00
|
|
|
widget.homeAssistant.panels.forEach((Panel panel) {
|
2019-03-13 17:23:23 +02:00
|
|
|
if (!panel.isHidden) {
|
|
|
|
menuItems.add(
|
|
|
|
new ListTile(
|
|
|
|
leading: Icon(MaterialDesignIcons.getIconDataFromIconName(panel.icon)),
|
|
|
|
title: Text("${panel.title}"),
|
|
|
|
onTap: () => panel.handleOpen(context)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2019-03-13 16:39:23 +02:00
|
|
|
});
|
2019-03-21 14:08:07 +02:00
|
|
|
}
|
2019-03-26 00:18:30 +02:00
|
|
|
//TODO check for loaded
|
|
|
|
menuItems.add(
|
2019-03-13 17:23:23 +02:00
|
|
|
new ListTile(
|
|
|
|
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:home-assistant")),
|
|
|
|
title: Text("Open Web UI"),
|
2019-04-05 13:06:14 +03:00
|
|
|
onTap: () => HAUtils.launchURL(Connection().httpWebHost),
|
2019-03-21 14:08:07 +02:00
|
|
|
)
|
2019-03-26 00:18:30 +02:00
|
|
|
);
|
2018-10-07 20:18:14 +03:00
|
|
|
menuItems.addAll([
|
2019-03-21 14:08:07 +02:00
|
|
|
Divider(),
|
2019-03-20 23:38:57 +02:00
|
|
|
ListTile(
|
|
|
|
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:login-variant")),
|
|
|
|
title: Text("Connection settings"),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
Navigator.of(context).pushNamed('/connection-settings', arguments: {"homeAssistant", widget.homeAssistant});
|
|
|
|
},
|
2019-03-21 14:08:07 +02:00
|
|
|
)
|
|
|
|
]);
|
|
|
|
menuItems.addAll([
|
2019-03-20 23:38:57 +02:00
|
|
|
Divider(),
|
2018-10-07 20:18:14 +03:00
|
|
|
new ListTile(
|
|
|
|
leading: Icon(Icons.insert_drive_file),
|
|
|
|
title: Text("Log"),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
Navigator.of(context).pushNamed('/log-view');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
new ListTile(
|
2019-02-22 15:15:27 +02:00
|
|
|
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:github-circle")),
|
2018-10-07 20:18:14 +03:00
|
|
|
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");
|
2018-10-07 20:18:14 +03:00
|
|
|
},
|
|
|
|
),
|
|
|
|
Divider(),
|
2019-03-14 14:07:36 +02:00
|
|
|
new ListTile(
|
2019-03-14 14:35:30 +02:00
|
|
|
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:discord")),
|
2019-03-14 14:07:36 +02:00
|
|
|
title: Text("Join Discord server"),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
HAUtils.launchURL("https://discord.gg/AUzEvwn");
|
|
|
|
},
|
|
|
|
),
|
2018-10-07 20:18:14 +03:00
|
|
|
new AboutListTile(
|
2018-11-17 23:02:05 +02:00
|
|
|
aboutBoxChildren: <Widget>[
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
2019-02-16 19:59:39 +02:00
|
|
|
HAUtils.launchURL("http://ha-client.homemade.systems/");
|
2018-11-17 23:02:05 +02:00
|
|
|
},
|
|
|
|
child: Text(
|
2019-02-16 19:59:39 +02:00
|
|
|
"ha-client.homemade.systems",
|
2018-11-17 23:02:05 +02:00
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.blue,
|
|
|
|
decoration: TextDecoration.underline
|
|
|
|
),
|
|
|
|
),
|
2019-04-04 21:43:23 +03:00
|
|
|
),
|
2019-04-04 21:54:41 +03:00
|
|
|
Container(
|
|
|
|
height: 10.0,
|
|
|
|
),
|
2019-04-04 21:43:23 +03:00
|
|
|
GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
HAUtils.launchURLInCustomTab(context, "http://ha-client.homemade.systems/terms_and_conditions");
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
"Terms and Conditions",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.blue,
|
|
|
|
decoration: TextDecoration.underline
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2019-04-04 21:54:41 +03:00
|
|
|
Container(
|
|
|
|
height: 10.0,
|
|
|
|
),
|
2019-04-04 21:43:23 +03:00
|
|
|
GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
HAUtils.launchURLInCustomTab(context, "http://ha-client.homemade.systems/privacy_policy");
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
"Privacy Policy",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.blue,
|
|
|
|
decoration: TextDecoration.underline
|
|
|
|
),
|
|
|
|
),
|
2018-11-17 23:02:05 +02:00
|
|
|
)
|
|
|
|
],
|
2018-10-07 20:18:14 +03:00
|
|
|
applicationName: appName,
|
2019-02-17 13:52:24 +02:00
|
|
|
applicationVersion: appVersion
|
2018-10-07 20:18:14 +03:00
|
|
|
)
|
|
|
|
]);
|
2018-09-16 14:58:21 +03:00
|
|
|
return new Drawer(
|
|
|
|
child: ListView(
|
2018-10-07 20:18:14 +03:00
|
|
|
children: menuItems,
|
2018-09-16 14:58:21 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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;
|
2018-11-23 16:30:42 +02:00
|
|
|
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(() {
|
2018-11-23 16:30:42 +02:00
|
|
|
_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
|
|
|
}
|
|
|
|
|
2019-04-19 21:43:52 +03:00
|
|
|
void _showErrorBottomBar(HAError error) {
|
2018-11-18 12:46:54 +02:00
|
|
|
TextStyle textStyle = TextStyle(
|
2019-04-19 21:43:52 +03:00
|
|
|
color: Colors.blue,
|
|
|
|
fontSize: Sizes.nameFontSize
|
2018-11-18 12:46:54 +02:00
|
|
|
);
|
|
|
|
_bottomBarColor = Colors.red.shade100;
|
2019-04-19 21:43:52 +03:00
|
|
|
List<Widget> actions = [];
|
|
|
|
error.actions.forEach((HAErrorAction action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case HAErrorActionType.FULL_RELOAD: {
|
|
|
|
actions.add(FlatButton(
|
|
|
|
child: Text("${action.title}", style: textStyle),
|
2018-09-20 23:21:03 +03:00
|
|
|
onPressed: () {
|
2019-04-05 11:48:41 +03:00
|
|
|
_fullLoad();
|
2019-03-20 23:05:25 +02:00
|
|
|
},
|
2019-04-19 21:43:52 +03:00
|
|
|
));
|
2019-03-20 23:05:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-19 21:43:52 +03:00
|
|
|
case HAErrorActionType.QUICK_RELOAD: {
|
|
|
|
actions.add(FlatButton(
|
|
|
|
child: Text("${action.title}", style: textStyle),
|
2019-03-20 23:05:25 +02:00
|
|
|
onPressed: () {
|
2019-04-19 21:43:52 +03:00
|
|
|
_quickLoad();
|
2019-03-20 23:05:25 +02:00
|
|
|
},
|
2019-04-19 21:43:52 +03:00
|
|
|
));
|
2019-03-20 23:05:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-19 21:43:52 +03:00
|
|
|
case HAErrorActionType.URL: {
|
|
|
|
actions.add(FlatButton(
|
|
|
|
child: Text("${action.title}", style: textStyle),
|
2019-03-20 23:05:25 +02:00
|
|
|
onPressed: () {
|
2019-04-19 21:43:52 +03:00
|
|
|
HAUtils.launchURLInCustomTab(context, "${action.url}");
|
2018-09-20 23:21:03 +03:00
|
|
|
},
|
2019-04-19 21:43:52 +03:00
|
|
|
));
|
2018-09-20 23:21:03 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-19 21:43:52 +03:00
|
|
|
case HAErrorActionType.OPEN_CONNECTION_SETTINGS: {
|
|
|
|
actions.add(FlatButton(
|
|
|
|
child: Text("${action.title}", style: textStyle),
|
2018-09-20 23:21:03 +03:00
|
|
|
onPressed: () {
|
2019-04-19 21:43:52 +03:00
|
|
|
Navigator.pushNamed(context, '/connection-settings');
|
2019-03-30 00:29:52 +02:00
|
|
|
},
|
2019-04-19 21:43:52 +03:00
|
|
|
));
|
2018-11-04 18:20:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-09-18 00:12:11 +03:00
|
|
|
}
|
2019-04-19 21:43:52 +03:00
|
|
|
});
|
|
|
|
if (actions.isNotEmpty) {
|
|
|
|
_bottomBarAction = Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: actions,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
_bottomBarAction = Container(height: 0.0, width: 0.0,);
|
|
|
|
}
|
|
|
|
setState(() {
|
|
|
|
_bottomBarProgress = false;
|
|
|
|
_bottomBarText = "${error.message}";
|
|
|
|
_showBottomBar = true;
|
|
|
|
});
|
2018-09-18 00:12:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
|
|
|
|
2018-11-14 18:03:50 +02:00
|
|
|
Widget _buildScaffoldBody(bool empty) {
|
2019-03-21 14:08:07 +02:00
|
|
|
List<PopupMenuItem<String>> popupMenuItems = [];
|
2019-03-26 00:18:30 +02:00
|
|
|
popupMenuItems.add(PopupMenuItem<String>(
|
|
|
|
child: new Text("Reload"),
|
|
|
|
value: "reload",
|
|
|
|
));
|
2019-04-05 13:39:54 +03:00
|
|
|
List<Widget> emptyBody = [
|
2019-04-05 14:07:03 +03:00
|
|
|
Text("."),
|
2019-04-05 13:39:54 +03:00
|
|
|
];
|
2019-04-05 13:06:14 +03:00
|
|
|
if (Connection().isAuthenticated) {
|
2019-04-05 13:39:54 +03:00
|
|
|
_showLoginButton = false;
|
2019-03-26 00:18:30 +02:00
|
|
|
popupMenuItems.add(
|
2019-03-21 14:08:07 +02:00
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: new Text("Logout"),
|
|
|
|
value: "logout",
|
2019-03-26 00:18:30 +02:00
|
|
|
));
|
2019-03-21 14:08:07 +02:00
|
|
|
}
|
2019-04-05 13:39:54 +03:00
|
|
|
if (_showLoginButton) {
|
|
|
|
emptyBody = [
|
|
|
|
FlatButton(
|
|
|
|
child: Text("Login with Home Assistant", style: TextStyle(fontSize: 16.0, color: Colors.white)),
|
|
|
|
color: Colors.blue,
|
|
|
|
onPressed: () => _showOAuth(),
|
|
|
|
)
|
|
|
|
];
|
|
|
|
}
|
2018-11-14 18:03:50 +02:00
|
|
|
return NestedScrollView(
|
|
|
|
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
|
|
|
|
return <Widget>[
|
|
|
|
SliverAppBar(
|
|
|
|
floating: true,
|
|
|
|
pinned: true,
|
|
|
|
primary: true,
|
2019-03-21 14:08:07 +02:00
|
|
|
title: Text(widget.homeAssistant.locationName ?? ""),
|
2019-02-10 22:33:46 +02:00
|
|
|
actions: <Widget>[
|
|
|
|
IconButton(
|
2019-02-22 15:15:27 +02:00
|
|
|
icon: Icon(MaterialDesignIcons.getIconDataFromIconName(
|
2019-02-10 22:33:46 +02:00
|
|
|
"mdi:dots-vertical"), color: Colors.white,),
|
|
|
|
onPressed: () {
|
|
|
|
showMenu(
|
|
|
|
position: RelativeRect.fromLTRB(MediaQuery.of(context).size.width, 70.0, 0.0, 0.0),
|
|
|
|
context: context,
|
2019-03-21 14:08:07 +02:00
|
|
|
items: popupMenuItems
|
2019-02-10 22:33:46 +02:00
|
|
|
).then((String val) {
|
|
|
|
if (val == "reload") {
|
2019-04-05 11:48:41 +03:00
|
|
|
_quickLoad();
|
2019-03-21 14:08:07 +02:00
|
|
|
} else if (val == "logout") {
|
2019-03-26 00:18:30 +02:00
|
|
|
widget.homeAssistant.logout().then((_) {
|
2019-04-05 11:48:41 +03:00
|
|
|
_quickLoad();
|
2019-03-21 14:08:07 +02:00
|
|
|
});
|
2019-02-10 22:33:46 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
)
|
|
|
|
],
|
2018-11-14 18:03:50 +02:00
|
|
|
leading: IconButton(
|
|
|
|
icon: Icon(Icons.menu),
|
|
|
|
onPressed: () {
|
|
|
|
_scaffoldKey.currentState.openDrawer();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
bottom: empty ? null : TabBar(
|
2019-02-21 15:35:58 +02:00
|
|
|
controller: _viewsTabController,
|
2018-11-14 18:03:50 +02:00
|
|
|
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,
|
2019-04-05 13:39:54 +03:00
|
|
|
children: emptyBody
|
2018-11-14 18:03:50 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
:
|
2019-03-20 12:48:00 +02:00
|
|
|
widget.homeAssistant.buildViews(context, _viewsTabController),
|
2018-09-24 22:54:51 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-21 15:35:58 +02:00
|
|
|
TabController _viewsTabController;
|
|
|
|
|
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) {
|
2018-11-23 16:30:42 +02:00
|
|
|
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
|
|
|
),
|
|
|
|
),
|
2018-11-23 16:30:42 +02:00
|
|
|
_bottomBarAction
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2018-11-18 12:46:54 +02:00
|
|
|
}
|
2018-09-16 14:58:21 +03:00
|
|
|
// This method is rerun every time setState is called.
|
2019-03-21 14:08:07 +02:00
|
|
|
if (widget.homeAssistant.isNoViews) {
|
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,
|
2019-03-02 20:13:24 +02:00
|
|
|
body: _buildScaffoldBody(true)
|
2018-11-14 18:03:50 +02:00
|
|
|
);
|
2018-09-16 14:58:21 +03:00
|
|
|
} 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,
|
2019-03-02 20:13:24 +02:00
|
|
|
body: HomeAssistantModel(
|
|
|
|
child: _buildScaffoldBody(false),
|
2019-03-20 12:48:00 +02:00
|
|
|
homeAssistant: widget.homeAssistant
|
2019-03-02 20:13:24 +02:00
|
|
|
),
|
2018-09-16 14:58:21 +03:00
|
|
|
);
|
|
|
|
}
|
2018-09-10 00:34:52 +03:00
|
|
|
}
|
2018-09-12 00:32:04 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2019-03-20 19:01:30 +02:00
|
|
|
final flutterWebviewPlugin = new FlutterWebviewPlugin();
|
|
|
|
flutterWebviewPlugin.dispose();
|
2018-09-16 19:24:26 +03:00
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
2019-03-20 19:01:30 +02:00
|
|
|
_viewsTabController?.dispose();
|
|
|
|
_stateSubscription?.cancel();
|
|
|
|
_settingsSubscription?.cancel();
|
|
|
|
_serviceCallSubscription?.cancel();
|
|
|
|
_showEntityPageSubscription?.cancel();
|
|
|
|
_showErrorSubscription?.cancel();
|
|
|
|
_startAuthSubscription?.cancel();
|
|
|
|
_reloadUISubscription?.cancel();
|
2019-03-26 00:18:30 +02:00
|
|
|
//TODO disconnect
|
|
|
|
//widget.homeAssistant?.disconnect();
|
2018-09-12 00:32:04 +03:00
|
|
|
super.dispose();
|
|
|
|
}
|
2018-09-10 00:34:52 +03:00
|
|
|
}
|