2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 02:05:29 +00:00

Main screen loading indicator (#183)

* Bug fix for login screen

- Prevent setState() from being called if the widget is no longer loaded

* Add callback function when API status changes

- Home screen uses this function to update connection status indicator

* Linting fixes
This commit is contained in:
Oliver
2022-07-19 23:10:06 +10:00
committed by GitHub
parent 7f3dfe7dd7
commit e03a8561b9
5 changed files with 74 additions and 5 deletions

View File

@ -135,6 +135,9 @@ class InvenTreeFileService extends FileService {
*/
/*
* API class which manages all communication with the InvenTree server
*/
class InvenTreeAPI {
factory InvenTreeAPI() {
@ -143,6 +146,19 @@ class InvenTreeAPI {
InvenTreeAPI._internal();
// List of callback functions to trigger when the connection status changes
List<Function()> _statusCallbacks = [];
// Register a callback function to be notified when the connection status changes
void registerCallback(Function() func) => _statusCallbacks.add(func);
void _connectionStatusChanged() {
for (Function() func in _statusCallbacks) {
// Call the function
func();
}
}
// Minimum required API version for server
static const _minApiVersion = 20;
@ -202,6 +218,10 @@ class InvenTreeAPI {
// Authentication token (initially empty, must be requested)
String _token = "";
String? get serverAddress {
return profile?.server;
}
bool get hasToken => _token.isNotEmpty;
/*
@ -457,6 +477,8 @@ class InvenTreeAPI {
// Clear received settings
_globalSettings.clear();
_userSettings.clear();
_connectionStatusChanged();
}
/*
@ -481,6 +503,8 @@ class InvenTreeAPI {
_connecting = true;
_connectionStatusChanged();
_connected = await _connect();
_connecting = false;
@ -493,6 +517,8 @@ class InvenTreeAPI {
);
}
_connectionStatusChanged();
return _connected;
}