2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 10:15:32 +00:00

Add a connection checker

This commit is contained in:
Oliver Walters
2020-04-06 22:33:38 +10:00
parent 0e35c370ba
commit 37cdf23ae1
3 changed files with 51 additions and 0 deletions

View File

@ -72,6 +72,41 @@ class InvenTreeAPI {
// Authentication token (initially empty, must be requested)
String _token = "";
bool isConnected() {
return _token.isNotEmpty;
}
/*
* Check server connection and display messages if not connected.
* Useful as a precursor check before performing operations.
*/
bool checkConnection(BuildContext context) {
// Firstly, is the server connected?
if (!isConnected()) {
showDialog(
context: context,
child: new SimpleDialog(
title: new Text("Not Connected"),
children: <Widget> [
ListTile(
title: Text("Server not connected"),
)
]
)
);
return false;
}
// Is the server version too old?
// TODO
// Finally
return true;
}
// Server instance information
String instance = '';