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

206 lines
8.4 KiB
Dart
Raw Normal View History

2018-09-10 00:34:52 +03:00
import 'dart:convert';
import 'dart:async';
2019-09-07 15:47:09 +03:00
import 'dart:math';
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';
2019-03-13 17:05:15 +02:00
import 'package:url_launcher/url_launcher.dart' as urlLauncher;
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;
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:progress_indicators/progress_indicators.dart';
2019-01-23 23:34:45 +02:00
import 'package:flutter_markdown/flutter_markdown.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';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
2019-03-30 00:29:52 +02:00
import 'package:device_info/device_info.dart';
2019-06-16 20:08:50 +03:00
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
2019-08-21 21:30:11 +03:00
import 'package:in_app_purchase/in_app_purchase.dart';
2019-09-08 19:04:12 +03:00
import 'plugins/circular_slider/single_circular_slider.dart';
import 'package:share/receive_share_state.dart';
import 'package:share/share.dart';
2019-09-08 19:04:12 +03:00
import 'utils/logger.dart';
2019-08-24 21:22:32 +03:00
part 'const.dart';
part 'utils/launcher.dart';
2019-08-24 21:22:32 +03:00
part 'entities/entity.class.dart';
part 'entities/entity_wrapper.class.dart';
part 'entities/timer/timer_entity.class.dart';
part 'entities/switch/switch_entity.class.dart';
part 'entities/button/button_entity.class.dart';
part 'entities/text/text_entity.class.dart';
part 'entities/climate/climate_entity.class.dart';
part 'entities/cover/cover_entity.class.dart';
part 'entities/date_time/date_time_entity.class.dart';
part 'entities/light/light_entity.class.dart';
part 'entities/select/select_entity.class.dart';
part 'entities/sun/sun_entity.class.dart';
part 'entities/sensor/sensor_entity.class.dart';
part 'entities/slider/slider_entity.dart';
part 'entities/media_player/media_player_entity.class.dart';
part 'entities/lock/lock_entity.class.dart';
part 'entities/group/group_entity.class.dart';
part 'entities/fan/fan_entity.class.dart';
part 'entities/automation/automation_entity.class.dart';
part 'entities/camera/camera_entity.class.dart';
part 'entities/alarm_control_panel/alarm_control_panel_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';
2019-03-12 23:35:33 +02:00
part 'entity_widgets/missed_entity.dart';
2019-09-07 18:23:04 +03:00
part 'cards/widgets/glance_card_entity_container.dart';
part 'cards/widgets/entity_button_card_body.widget.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';
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';
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';
2019-08-24 21:22:32 +03:00
part 'entities/switch/widget/switch_state.dart';
part 'entities/slider/widgets/slider_controls.dart';
part 'entities/text/widgets/text_input_state.dart';
part 'entities/select/widgets/select_state.dart';
part 'entity_widgets/common/simple_state.dart';
part 'entities/timer/widgets/timer_state.dart';
part 'entities/climate/widgets/climate_state.widget.dart';
part 'entities/cover/widgets/cover_state.dart';
part 'entities/date_time/widgets/date_time_state.dart';
part 'entities/lock/widgets/lock_state.dart';
part 'entities/climate/widgets/climate_controls.dart';
part 'entities/climate/widgets/temperature_control_widget.dart';
2019-08-24 21:22:32 +03:00
part 'entities/cover/widgets/cover_controls.widget.dart';
part 'entities/light/widgets/light_controls.dart';
part 'entities/media_player/widgets/media_player_widgets.dart';
part 'entities/fan/widgets/fan_controls.dart';
part 'entities/alarm_control_panel/widgets/alarm_control_panel_controls.widget.dart';
part 'pages/settings.page.dart';
part 'pages/purchase.page.dart';
part 'pages/widgets/product_purchase.widget.dart';
part 'pages/widgets/page_loading_indicator.dart';
part 'pages/widgets/page_loading_error.dart';
2019-08-24 21:22:32 +03:00
part 'pages/panel.page.dart';
2019-09-05 00:25:03 +03:00
part 'pages/main.page.dart';
part 'home_assistant.class.dart';
2019-08-24 21:22:32 +03:00
part 'pages/log.page.dart';
part 'pages/entity.page.dart';
2018-09-25 22:47:06 +03:00
part 'mdi.class.dart';
2018-09-26 22:16:50 +03:00
part 'entity_collection.class.dart';
part 'managers/auth_manager.class.dart';
part 'managers/location_manager.class.dart';
2019-08-31 22:06:52 +03:00
part 'managers/mobile_app_integration_manager.class.dart';
part 'managers/connection_manager.class.dart';
part 'managers/device_info_manager.class.dart';
2019-08-31 23:55:32 +03:00
part 'managers/startup_user_messages_manager.class.dart';
2019-09-07 18:23:04 +03:00
part 'ui.dart';
part 'view.class.dart';
2019-09-07 15:47:09 +03:00
part 'cards/card.class.dart';
2019-09-07 18:23:04 +03:00
part 'panels/panel_class.dart';
part 'view.dart';
part 'cards/card_widget.dart';
part 'cards/widgets/card_header.widget.dart';
part 'panels/config_panel_widget.dart';
part 'panels/widgets/link_to_web_config.dart';
2019-09-05 00:17:08 +03:00
part 'types/ha_error.dart';
part 'types/event_bus_events.dart';
2019-09-07 15:47:09 +03:00
part 'cards/widgets/gauge_card_body.dart';
2019-09-08 19:04:12 +03:00
part 'cards/widgets/light_card_body.dart';
part 'pages/play_media.page.dart';
2018-09-10 00:34:52 +03:00
EventBus eventBus = new EventBus();
2019-03-30 00:29:52 +02:00
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
2019-06-16 20:08:50 +03:00
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
const String appName = "HA Client";
2019-09-18 21:18:24 +03:00
const appVersion = "0.6.7";
2019-08-28 19:23:04 +03:00
void main() async {
FlutterError.onError = (errorDetails) {
Logger.e( "${errorDetails.exception}");
if (Logger.isInDebugMode) {
FlutterError.dumpErrorToConsole(errorDetails);
}
};
runZoned(() {
//AndroidAlarmManager.initialize().then((_) {
runApp(new HAClientApp());
// print("Running MAIN isolate ${Isolate.current.hashCode}");
//});
2019-08-28 19:23:04 +03:00
}, onError: (error, stack) {
Logger.e("$error");
Logger.e("$stack");
if (Logger.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: {
2019-09-01 00:12:16 +03:00
"/": (context) => MainPage(title: 'HA Client'),
2018-10-27 00:54:05 +03:00
"/connection-settings": (context) => ConnectionSettingsPage(title: "Settings"),
2019-08-23 14:13:58 +03:00
"/putchase": (context) => PurchasePage(title: "Support app development"),
2019-09-09 14:24:54 +03:00
"/play-media": (context) => PlayMediaPage(mediaUrl: "${ModalRoute.of(context).settings.arguments != null ? (ModalRoute.of(context).settings.arguments as Map)['url'] : ''}",),
2019-06-16 22:57:50 +03:00
"/log-view": (context) => LogViewPage(title: "Log"),
2019-08-26 18:04:40 +03:00
"/login": (context) => WebviewScaffold(
url: "${ConnectionManager().oauthUrl}",
2019-06-16 22:57:50 +03:00
appBar: new AppBar(
leading: IconButton(
icon: Icon(Icons.help),
onPressed: () => Launcher.launchURLInCustomTab(context: context, url: "http://ha-client.homemade.systems/docs#authentication")
2019-06-16 22:57:50 +03:00
),
2019-08-26 18:04:40 +03:00
title: new Text("Login with HA"),
actions: <Widget>[
FlatButton(
child: Text("Manual", style: TextStyle(color: Colors.white)),
onPressed: () {
eventBus.fire(ShowPageEvent(path: "/connection-settings", goBackFirst: true));
2019-08-26 18:04:40 +03:00
},
)
],
2019-06-16 22:57:50 +03:00
),
),
"/webview": (context) => WebviewScaffold(
url: "${(ModalRoute.of(context).settings.arguments as Map)['url']}",
appBar: new AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => Navigator.of(context).pop()
),
title: new Text("${(ModalRoute.of(context).settings.arguments as Map)['title']}"),
),
2019-06-16 22:57:50 +03:00
)
},
2018-09-10 00:34:52 +03:00
);
}
2019-09-05 00:25:03 +03:00
}