mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-01-13 03:26:24 +00:00
Add a connection checker
This commit is contained in:
parent
0e35c370ba
commit
37cdf23ae1
3 changed files with 51 additions and 0 deletions
35
lib/api.dart
35
lib/api.dart
|
|
@ -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 = '';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue