2018-09-10 00:34:52 +03:00
|
|
|
import 'dart:convert';
|
2018-09-15 01:46:15 +03:00
|
|
|
import 'dart:async';
|
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-15 01:46:15 +03:00
|
|
|
import 'package:progress_indicators/progress_indicators.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-10 03:06:35 +03:00
|
|
|
|
|
|
|
part 'settings.dart';
|
2018-09-15 01:46:15 +03:00
|
|
|
part 'data_model.dart';
|
2018-09-10 00:34:52 +03:00
|
|
|
|
2018-09-16 18:02:12 +03:00
|
|
|
EventBus eventBus = new EventBus();
|
2018-09-18 23:21:05 +03:00
|
|
|
const String appName = "HA Client";
|
2018-09-19 00:24:32 +03:00
|
|
|
const appVersion = "0.0.8";
|
2018-09-16 18:02:12 +03:00
|
|
|
|
2018-09-12 00:32:04 +03:00
|
|
|
void main() => runApp(new HassClientApp());
|
2018-09-10 00:34:52 +03:00
|
|
|
|
2018-09-12 00:32:04 +03:00
|
|
|
class HassClientApp 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(
|
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: {
|
|
|
|
"/": (context) => MainPage(title: 'Hass Client'),
|
2018-09-17 00:28:19 +03:00
|
|
|
"/connection-settings": (context) => ConnectionSettingsPage(title: "Connection Settings")
|
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 {
|
|
|
|
MainPage({Key key, this.title}) : super(key: key);
|
2018-09-10 00:34:52 +03:00
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
@override
|
2018-09-10 03:06:35 +03:00
|
|
|
_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 {
|
2018-09-15 01:46:15 +03:00
|
|
|
HassioDataModel _dataModel;
|
|
|
|
Map _entitiesData;
|
2018-09-15 12:56:42 +03:00
|
|
|
Map _uiStructure;
|
2018-09-17 00:28:19 +03:00
|
|
|
Map _instanceConfig;
|
2018-09-16 14:58:21 +03:00
|
|
|
int _uiViewsCount = 0;
|
2018-09-17 00:28:19 +03:00
|
|
|
String _instanceHost;
|
2018-09-20 23:21:03 +03:00
|
|
|
int _errorCodeToBeShown = 0;
|
|
|
|
String _lastErrorMessage = "";
|
|
|
|
StreamSubscription _stateSubscription;
|
|
|
|
bool _isLoading = true;
|
2018-09-16 00:06:07 +03:00
|
|
|
Map _stateIconColors = {
|
|
|
|
"on": Colors.amber,
|
|
|
|
"off": Colors.blueGrey,
|
|
|
|
"unavailable": Colors.black12,
|
|
|
|
"unknown": Colors.black12,
|
|
|
|
"playing": Colors.amber
|
|
|
|
};
|
2018-09-10 03:06:35 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2018-09-16 19:24:26 +03:00
|
|
|
WidgetsBinding.instance.addObserver(this);
|
2018-09-20 23:21:03 +03:00
|
|
|
eventBus.on<SettingsChangedEvent>().listen((event) {
|
|
|
|
debugPrint("Settings change event: reconnect=${event.reconnect}");
|
|
|
|
setState(() {
|
|
|
|
_errorCodeToBeShown = 0;
|
|
|
|
});
|
|
|
|
_initConnection();
|
|
|
|
});
|
|
|
|
_initConnection();
|
2018-09-10 03:06:35 +03:00
|
|
|
}
|
2018-09-10 00:34:52 +03:00
|
|
|
|
2018-09-16 19:24:26 +03:00
|
|
|
@override
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
|
debugPrint("$state");
|
|
|
|
if (state == AppLifecycleState.resumed) {
|
|
|
|
_refreshData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 23:21:03 +03:00
|
|
|
_initConnection() async {
|
2018-09-10 03:06:35 +03:00
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
2018-09-17 00:28:19 +03:00
|
|
|
String domain = prefs.getString('hassio-domain');
|
|
|
|
String port = prefs.getString('hassio-port');
|
2018-09-17 22:20:36 +03:00
|
|
|
_instanceHost = "$domain:$port";
|
2018-09-20 23:21:03 +03:00
|
|
|
String apiEndpoint = "${prefs.getString('hassio-protocol')}://$domain:$port/api/websocket";
|
|
|
|
String apiPassword = prefs.getString('hassio-password');
|
|
|
|
if ((domain == null) || (port == null) || (apiEndpoint == null) || (apiPassword == null) ||
|
|
|
|
(domain.length == 0) || (port.length == 0) || (apiEndpoint.length == 0) || (apiPassword.length == 0)) {
|
|
|
|
setState(() {
|
|
|
|
_errorCodeToBeShown = 5;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (_dataModel != null) _dataModel.closeConnection();
|
|
|
|
_createConnection(apiEndpoint, apiPassword);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_createConnection(String apiEndpoint, String apiPassword) {
|
|
|
|
_dataModel = HassioDataModel(apiEndpoint, apiPassword);
|
2018-09-17 01:03:34 +03:00
|
|
|
_refreshData();
|
2018-09-20 23:21:03 +03:00
|
|
|
if (_stateSubscription != null) _stateSubscription.cancel();
|
|
|
|
_stateSubscription = eventBus.on<StateChangedEvent>().listen((event) {
|
2018-09-16 18:02:12 +03:00
|
|
|
debugPrint("State change event for ${event.entityId}");
|
|
|
|
setState(() {
|
|
|
|
_entitiesData = _dataModel.entities;
|
|
|
|
});
|
|
|
|
});
|
2018-09-12 00:32:04 +03:00
|
|
|
}
|
|
|
|
|
2018-09-15 01:46:15 +03:00
|
|
|
_refreshData() async {
|
2018-09-12 00:32:04 +03:00
|
|
|
setState(() {
|
2018-09-20 23:21:03 +03:00
|
|
|
_isLoading = true;
|
2018-09-12 00:32:04 +03:00
|
|
|
});
|
2018-09-20 23:21:03 +03:00
|
|
|
_errorCodeToBeShown = 0;
|
2018-09-15 01:46:15 +03:00
|
|
|
if (_dataModel != null) {
|
|
|
|
await _dataModel.fetch().then((result) {
|
|
|
|
setState(() {
|
2018-09-17 00:28:19 +03:00
|
|
|
_instanceConfig = _dataModel.instanceConfig;
|
2018-09-15 12:56:42 +03:00
|
|
|
_entitiesData = _dataModel.entities;
|
|
|
|
_uiStructure = _dataModel.uiStructure;
|
2018-09-16 14:58:21 +03:00
|
|
|
_uiViewsCount = _uiStructure.length;
|
2018-09-20 23:21:03 +03:00
|
|
|
_isLoading = false;
|
2018-09-15 01:46:15 +03:00
|
|
|
});
|
|
|
|
}).catchError((e) {
|
2018-09-21 00:01:53 +03:00
|
|
|
_setErrorState(e);
|
2018-09-12 00:32:04 +03:00
|
|
|
});
|
2018-09-15 01:46:15 +03:00
|
|
|
}
|
2018-09-11 01:09:21 +03:00
|
|
|
}
|
|
|
|
|
2018-09-21 00:01:53 +03:00
|
|
|
_setErrorState(e) {
|
|
|
|
setState(() {
|
|
|
|
_errorCodeToBeShown = e["errorCode"] != null ? e["errorCode"] : 99;
|
|
|
|
_lastErrorMessage = e["errorMessage"] ?? "Unknown error";
|
|
|
|
_isLoading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void _callService(String domain, String service, String entityId) {
|
|
|
|
setState(() {
|
|
|
|
_isLoading = true;
|
|
|
|
});
|
|
|
|
_dataModel.callService(domain, service, entityId).then((r) {
|
|
|
|
setState(() {
|
|
|
|
_isLoading = false;
|
|
|
|
});
|
|
|
|
}).catchError((e) => _setErrorState(e));
|
|
|
|
}
|
|
|
|
|
2018-09-15 12:56:42 +03:00
|
|
|
Widget _buildEntityAction(String entityId) {
|
|
|
|
var entity = _entitiesData[entityId];
|
2018-09-16 00:06:07 +03:00
|
|
|
Widget result;
|
2018-09-15 12:56:42 +03:00
|
|
|
if (entity["actionType"] == "switch") {
|
2018-09-16 00:06:07 +03:00
|
|
|
result = Switch(
|
2018-09-15 12:56:42 +03:00
|
|
|
value: (entity["state"] == "on"),
|
|
|
|
onChanged: ((state) {
|
2018-09-21 00:01:53 +03:00
|
|
|
_callService(
|
2018-09-16 00:06:07 +03:00
|
|
|
entity["domain"], state ? "turn_on" : "turn_off", entityId);
|
2018-09-15 12:56:42 +03:00
|
|
|
setState(() {
|
|
|
|
_entitiesData[entityId]["state"] = state ? "on" : "off";
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
2018-09-16 00:06:07 +03:00
|
|
|
} else if (entity["actionType"] == "statelessIcon") {
|
|
|
|
result = SizedBox(
|
|
|
|
width: 60.0,
|
|
|
|
child: FlatButton(
|
|
|
|
onPressed: (() {
|
2018-09-21 00:01:53 +03:00
|
|
|
_callService(entity["domain"], "turn_on", entityId);
|
2018-09-16 00:06:07 +03:00
|
|
|
}),
|
|
|
|
child: Text(
|
|
|
|
"Run",
|
|
|
|
textAlign: TextAlign.right,
|
|
|
|
style: new TextStyle(fontSize: 16.0, color: Colors.blue),
|
2018-09-15 12:56:42 +03:00
|
|
|
),
|
2018-09-16 00:06:07 +03:00
|
|
|
));
|
2018-09-15 12:56:42 +03:00
|
|
|
} else {
|
2018-09-16 00:06:07 +03:00
|
|
|
result = Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 0.0, 16.0, 0.0),
|
|
|
|
child: Text(
|
|
|
|
"${entity["state"]}${(entity["attributes"] != null && entity["attributes"]["unit_of_measurement"] != null) ? entity["attributes"]["unit_of_measurement"] : ''}",
|
|
|
|
textAlign: TextAlign.right,
|
|
|
|
style: new TextStyle(
|
|
|
|
fontSize: 16.0,
|
|
|
|
)));
|
2018-09-15 12:56:42 +03:00
|
|
|
}
|
2018-09-16 00:06:07 +03:00
|
|
|
/*return SizedBox(
|
|
|
|
width: 60.0,
|
|
|
|
// height: double.infinity,
|
|
|
|
child: result
|
|
|
|
);*/
|
|
|
|
return result;
|
|
|
|
}
|
2018-09-15 12:56:42 +03:00
|
|
|
|
2018-09-16 14:58:21 +03:00
|
|
|
Card _buildCard(List<String> ids, String name) {
|
2018-09-15 12:56:42 +03:00
|
|
|
List<Widget> body = [];
|
2018-09-16 14:58:21 +03:00
|
|
|
body.add(_buildCardHeader(name));
|
|
|
|
body.addAll(_buildCardBody(ids));
|
2018-09-16 00:06:07 +03:00
|
|
|
Card result =
|
|
|
|
Card(child: new Column(mainAxisSize: MainAxisSize.min, children: body));
|
2018-09-15 12:56:42 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-16 14:58:21 +03:00
|
|
|
Widget _buildCardHeader(String name) {
|
2018-09-15 12:56:42 +03:00
|
|
|
var result;
|
|
|
|
if (name.length > 0) {
|
|
|
|
result = new ListTile(
|
|
|
|
//leading: const Icon(Icons.device_hub),
|
|
|
|
//subtitle: Text(".."),
|
|
|
|
//trailing: Text("${data["state"]}"),
|
2018-09-16 00:06:07 +03:00
|
|
|
title: Text("$name",
|
2018-09-15 12:56:42 +03:00
|
|
|
textAlign: TextAlign.left,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
2018-09-16 00:06:07 +03:00
|
|
|
style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 25.0)),
|
2018-09-15 12:56:42 +03:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
result = new Container(width: 0.0, height: 0.0);
|
|
|
|
}
|
|
|
|
return result;
|
2018-09-10 00:34:52 +03:00
|
|
|
}
|
|
|
|
|
2018-09-16 14:58:21 +03:00
|
|
|
List<Widget> _buildCardBody(List<String> ids) {
|
2018-09-15 12:56:42 +03:00
|
|
|
List<Widget> entities = [];
|
2018-09-16 00:06:07 +03:00
|
|
|
ids.forEach((id) {
|
2018-09-15 12:56:42 +03:00
|
|
|
var data = _entitiesData[id];
|
2018-09-17 22:20:36 +03:00
|
|
|
if (data == null) {
|
|
|
|
debugPrint("Hiding unknown entity from card: $id");
|
|
|
|
} else {
|
|
|
|
entities.add(new ListTile(
|
|
|
|
leading: Icon(
|
|
|
|
_createMDIfromCode(data["iconCode"]),
|
|
|
|
color: _stateIconColors[data["state"]] ?? Colors.blueGrey,
|
|
|
|
),
|
|
|
|
//subtitle: Text("${data['entity_id']}"),
|
|
|
|
trailing: _buildEntityAction(id),
|
|
|
|
title: Text(
|
|
|
|
"${data["display_name"]}",
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
2018-09-15 12:56:42 +03:00
|
|
|
});
|
|
|
|
return entities;
|
2018-09-12 22:31:58 +03:00
|
|
|
}
|
2018-09-10 00:34:52 +03:00
|
|
|
|
2018-09-16 14:58:21 +03:00
|
|
|
List<Widget> buildSingleView(structure) {
|
2018-09-15 01:46:15 +03:00
|
|
|
List<Widget> result = [];
|
2018-09-16 15:32:17 +03:00
|
|
|
structure["standalone"].forEach((entityId) {
|
|
|
|
result.add(_buildCard([entityId], ""));
|
|
|
|
});
|
|
|
|
structure["groups"].forEach((group) {
|
|
|
|
result.add(_buildCard(
|
|
|
|
group["children"], group["friendly_name"].toString()));
|
|
|
|
});
|
|
|
|
|
2018-09-15 01:46:15 +03:00
|
|
|
return result;
|
2018-09-16 14:58:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
List<ListView> buildUIViews() {
|
|
|
|
List<ListView> result = [];
|
|
|
|
if ((_entitiesData != null) && (_uiStructure != null)) {
|
|
|
|
_uiStructure.forEach((viewId, structure) {
|
|
|
|
result.add(ListView(
|
|
|
|
children: buildSingleView(structure),
|
|
|
|
));
|
|
|
|
});
|
2018-09-15 01:46:15 +03:00
|
|
|
}
|
2018-09-16 14:58:21 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-16 16:12:09 +03:00
|
|
|
IconData _createMDIfromCode(int code) {
|
|
|
|
return IconData(code, fontFamily: 'Material Design Icons');
|
|
|
|
}
|
|
|
|
|
2018-09-16 14:58:21 +03:00
|
|
|
List<Tab> buildUIViewTabs() {
|
|
|
|
List<Tab> result = [];
|
|
|
|
if ((_entitiesData != null) && (_uiStructure != null)) {
|
|
|
|
_uiStructure.forEach((viewId, structure) {
|
|
|
|
result.add(
|
2018-09-17 22:20:36 +03:00
|
|
|
Tab(
|
|
|
|
icon: Icon(_createMDIfromCode(structure["iconCode"]))
|
|
|
|
)
|
2018-09-16 14:58:21 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
2018-09-15 01:46:15 +03:00
|
|
|
}
|
|
|
|
|
2018-09-18 00:12:11 +03:00
|
|
|
Widget _buildAppTitle() {
|
2018-09-15 01:46:15 +03:00
|
|
|
Row titleRow = Row(
|
2018-09-17 01:03:34 +03:00
|
|
|
children: [Text(_instanceConfig != null ? _instanceConfig["location_name"] : "")],
|
2018-09-15 01:46:15 +03:00
|
|
|
);
|
2018-09-20 23:21:03 +03:00
|
|
|
if (_isLoading) {
|
2018-09-15 01:46:15 +03:00
|
|
|
titleRow.children.add(Padding(
|
|
|
|
child: JumpingDotsProgressIndicator(
|
2018-09-17 00:28:19 +03:00
|
|
|
fontSize: 26.0,
|
2018-09-15 01:46:15 +03:00
|
|
|
color: Colors.white,
|
|
|
|
),
|
2018-09-17 00:28:19 +03:00
|
|
|
padding: const EdgeInsets.fromLTRB(5.0, 0.0, 0.0, 30.0),
|
2018-09-16 00:06:07 +03:00
|
|
|
));
|
2018-09-15 01:46:15 +03:00
|
|
|
}
|
|
|
|
return titleRow;
|
2018-09-10 00:34:52 +03:00
|
|
|
}
|
|
|
|
|
2018-09-16 14:58:21 +03:00
|
|
|
Drawer _buildAppDrawer() {
|
|
|
|
return new Drawer(
|
|
|
|
child: ListView(
|
|
|
|
children: <Widget>[
|
|
|
|
new UserAccountsDrawerHeader(
|
2018-09-17 00:28:19 +03:00
|
|
|
accountName: Text(_instanceConfig != null ? _instanceConfig["location_name"] : "Unknown"),
|
|
|
|
accountEmail: Text(_instanceHost ?? "Not configured"),
|
|
|
|
currentAccountPicture: new Image.asset('images/hassio-192x192.png'),
|
2018-09-16 14:58:21 +03:00
|
|
|
),
|
|
|
|
new ListTile(
|
|
|
|
leading: Icon(Icons.settings),
|
2018-09-17 00:28:19 +03:00
|
|
|
title: Text("Connection settings"),
|
2018-09-16 14:58:21 +03:00
|
|
|
onTap: () {
|
2018-09-17 00:28:19 +03:00
|
|
|
Navigator.pushNamed(context, '/connection-settings');
|
2018-09-16 14:58:21 +03:00
|
|
|
},
|
|
|
|
),
|
|
|
|
new AboutListTile(
|
2018-09-17 01:03:34 +03:00
|
|
|
applicationName: appName,
|
|
|
|
applicationVersion: appVersion,
|
2018-09-16 14:58:21 +03:00
|
|
|
applicationLegalese: "Keyboard Crumbs",
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-18 00:12:11 +03:00
|
|
|
_checkShowInfo(BuildContext context) {
|
2018-09-20 23:21:03 +03:00
|
|
|
if (_errorCodeToBeShown > 0) {
|
|
|
|
String message = _lastErrorMessage;
|
2018-09-18 00:12:11 +03:00
|
|
|
SnackBarAction action;
|
2018-09-20 23:21:03 +03:00
|
|
|
switch (_errorCodeToBeShown) {
|
2018-09-18 00:12:11 +03:00
|
|
|
case 1: {
|
|
|
|
action = SnackBarAction(
|
|
|
|
label: "Retry",
|
2018-09-20 23:21:03 +03:00
|
|
|
onPressed: () {
|
|
|
|
_scaffoldKey?.currentState?.hideCurrentSnackBar();
|
|
|
|
_refreshData();
|
|
|
|
},
|
2018-09-18 00:12:11 +03:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2018-09-20 23:21:03 +03:00
|
|
|
|
|
|
|
case 5: {
|
|
|
|
message = "Check connection settings";
|
|
|
|
action = SnackBarAction(
|
|
|
|
label: "Open",
|
|
|
|
onPressed: () {
|
|
|
|
_scaffoldKey?.currentState?.hideCurrentSnackBar();
|
|
|
|
Navigator.pushNamed(context, '/connection-settings');
|
|
|
|
},
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 6: {
|
|
|
|
action = SnackBarAction(
|
|
|
|
label: "Settings",
|
|
|
|
onPressed: () {
|
|
|
|
_scaffoldKey?.currentState?.hideCurrentSnackBar();
|
|
|
|
Navigator.pushNamed(context, '/connection-settings');
|
|
|
|
},
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 7: {
|
|
|
|
action = SnackBarAction(
|
|
|
|
label: "Retry",
|
|
|
|
onPressed: () {
|
|
|
|
_scaffoldKey?.currentState?.hideCurrentSnackBar();
|
|
|
|
_refreshData();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2018-09-21 00:01:53 +03:00
|
|
|
|
|
|
|
case 8: {
|
|
|
|
action = SnackBarAction(
|
|
|
|
label: "Reconnect",
|
|
|
|
onPressed: () {
|
|
|
|
_scaffoldKey?.currentState?.hideCurrentSnackBar();
|
|
|
|
_refreshData();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2018-09-18 00:12:11 +03:00
|
|
|
}
|
|
|
|
Timer(Duration(seconds: 1), () {
|
|
|
|
_scaffoldKey.currentState.hideCurrentSnackBar();
|
|
|
|
_scaffoldKey.currentState.showSnackBar(
|
|
|
|
SnackBar(
|
2018-09-20 23:21:03 +03:00
|
|
|
content: Text("$message (code: $_errorCodeToBeShown)"),
|
2018-09-18 00:12:11 +03:00
|
|
|
action: action,
|
|
|
|
duration: Duration(hours: 1),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
|
|
|
|
2018-09-10 00:34:52 +03:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2018-09-18 00:12:11 +03:00
|
|
|
_checkShowInfo(context);
|
2018-09-16 14:58:21 +03:00
|
|
|
// This method is rerun every time setState is called.
|
2018-09-10 00:34:52 +03:00
|
|
|
//
|
2018-09-16 14:58:21 +03:00
|
|
|
if (_entitiesData == null) {
|
|
|
|
return new Scaffold(
|
2018-09-18 00:12:11 +03:00
|
|
|
key: _scaffoldKey,
|
2018-09-16 14:58:21 +03:00
|
|
|
appBar: new AppBar(
|
2018-09-18 00:12:11 +03:00
|
|
|
title: _buildAppTitle()
|
2018-09-16 14:58:21 +03:00
|
|
|
),
|
|
|
|
drawer: _buildAppDrawer(),
|
2018-09-16 16:12:09 +03:00
|
|
|
body: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2018-09-18 00:12:11 +03:00
|
|
|
/*Padding(
|
2018-09-16 16:12:09 +03:00
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 10.0),
|
|
|
|
child: Text(
|
2018-09-18 00:12:11 +03:00
|
|
|
_fetchErrorCode > 0 ? "Well... no.\n\nThere was an error [$_fetchErrorCode]: ${_getErrorMessageByCode(_fetchErrorCode, false)}" : "Loading...",
|
2018-09-16 16:12:09 +03:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(fontSize: 16.0),
|
|
|
|
),
|
2018-09-18 00:12:11 +03:00
|
|
|
),*/
|
|
|
|
Icon(
|
|
|
|
_createMDIfromCode(MaterialDesignIcons.getCustomIconByName("mdi:home-assistant")),
|
|
|
|
size: 100.0,
|
2018-09-20 23:21:03 +03:00
|
|
|
color: _errorCodeToBeShown == 0 ? Colors.blue : Colors.redAccent,
|
2018-09-16 16:12:09 +03:00
|
|
|
),
|
|
|
|
]
|
|
|
|
),
|
|
|
|
),
|
2018-09-16 14:58:21 +03:00
|
|
|
floatingActionButton: new FloatingActionButton(
|
|
|
|
onPressed: _refreshData,
|
|
|
|
tooltip: 'Increment',
|
|
|
|
child: new Icon(Icons.refresh),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return DefaultTabController(
|
|
|
|
length: _uiViewsCount,
|
|
|
|
child: new Scaffold(
|
2018-09-18 00:12:11 +03:00
|
|
|
key: _scaffoldKey,
|
2018-09-16 14:58:21 +03:00
|
|
|
appBar: new AppBar(
|
|
|
|
// Here we take the value from the MyHomePage object that was created by
|
|
|
|
// the App.build method, and use it to set our appbar title.
|
2018-09-18 00:12:11 +03:00
|
|
|
title: _buildAppTitle(),
|
2018-09-16 14:58:21 +03:00
|
|
|
bottom: TabBar(
|
|
|
|
tabs: buildUIViewTabs()
|
2018-09-16 00:06:07 +03:00
|
|
|
),
|
2018-09-10 03:06:35 +03:00
|
|
|
),
|
2018-09-16 14:58:21 +03:00
|
|
|
drawer: _buildAppDrawer(),
|
|
|
|
body: TabBarView(
|
|
|
|
children: buildUIViews()
|
2018-09-10 01:25:25 +03:00
|
|
|
),
|
2018-09-16 14:58:21 +03:00
|
|
|
floatingActionButton: new FloatingActionButton(
|
|
|
|
onPressed: _refreshData,
|
|
|
|
tooltip: 'Increment',
|
|
|
|
child: new Icon(Icons.refresh),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2018-09-10 00:34:52 +03:00
|
|
|
}
|
2018-09-12 00:32:04 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2018-09-16 19:24:26 +03:00
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
_dataModel.closeConnection();
|
2018-09-12 00:32:04 +03:00
|
|
|
super.dispose();
|
|
|
|
}
|
2018-09-10 00:34:52 +03:00
|
|
|
}
|