mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
Optimized single server status update
This commit is contained in:
@@ -55,7 +55,11 @@ class ServerProvider extends BusyProvider {
|
|||||||
passwordOrKey: spi.authorization);
|
passwordOrKey: spi.authorization);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refreshData() async {
|
Future<void> refreshData({int? idx}) async {
|
||||||
|
if (idx != null) {
|
||||||
|
_servers[idx].status = await _getData(_servers[idx].info, idx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
List<ServerStatus> _serversStatus = [];
|
List<ServerStatus> _serversStatus = [];
|
||||||
try {
|
try {
|
||||||
_serversStatus = await Future.wait(
|
_serversStatus = await Future.wait(
|
||||||
@@ -85,14 +89,13 @@ class ServerProvider extends BusyProvider {
|
|||||||
_servers.add(genInfo(info));
|
_servers.add(genInfo(info));
|
||||||
locator<ServerStore>().put(info);
|
locator<ServerStore>().put(info);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
refreshData();
|
refreshData(idx: _servers.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delServer(ServerPrivateInfo info) {
|
void delServer(ServerPrivateInfo info) {
|
||||||
_servers.removeWhere((e) => e.info == info);
|
_servers.removeWhere((e) => e.info == info);
|
||||||
locator<ServerStore>().delete(info);
|
locator<ServerStore>().delete(info);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
refreshData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateServer(ServerPrivateInfo old, ServerPrivateInfo newInfo) {
|
void updateServer(ServerPrivateInfo old, ServerPrivateInfo newInfo) {
|
||||||
@@ -101,7 +104,7 @@ class ServerProvider extends BusyProvider {
|
|||||||
_servers[idx].client = genClient(newInfo);
|
_servers[idx].client = genClient(newInfo);
|
||||||
locator<ServerStore>().update(old, newInfo);
|
locator<ServerStore>().update(old, newInfo);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
refreshData();
|
refreshData(idx: idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ServerStatus> _getData(ServerPrivateInfo info, int idx) async {
|
Future<ServerStatus> _getData(ServerPrivateInfo info, int idx) async {
|
||||||
|
|||||||
Reference in New Issue
Block a user