android ensure clients sync;new client scrollToBottom

This commit is contained in:
csf
2022-04-19 21:15:19 +08:00
parent 11a1b12fe7
commit 59e7d53e7d
2 changed files with 54 additions and 29 deletions

View File

@@ -41,6 +41,8 @@ class ServerModel with ChangeNotifier {
Map<int, Client> get clients => _clients;
final controller = ScrollController();
ServerModel() {
() async {
/**
@@ -95,6 +97,12 @@ class ServerModel with ChangeNotifier {
_connectStatus = status;
notifyListeners();
}
final res =
FFI.getByName('check_clients_length', _clients.length.toString());
if (res.isNotEmpty) {
debugPrint("clients not match!");
updateClientState(res);
}
});
}
@@ -294,8 +302,8 @@ class ServerModel with ChangeNotifier {
notifyListeners();
}
updateClientState() {
var res = FFI.getByName("clients_state");
updateClientState([String? json]) {
var res = json ?? FFI.getByName("clients_state");
try {
final List clientsJson = jsonDecode(res);
for (var clientJson in clientsJson) {
@@ -315,6 +323,7 @@ class ServerModel with ChangeNotifier {
return;
}
_clients[client.id] = client;
scrollToBottom();
notifyListeners();
showLoginDialog(client);
} catch (e) {
@@ -368,6 +377,14 @@ class ServerModel with ChangeNotifier {
tag: getLoginDialogTag(client.id));
}
scrollToBottom() {
Future.delayed(Duration(milliseconds: 200), () {
controller.animateTo(controller.position.maxScrollExtent,
duration: Duration(milliseconds: 200),
curve: Curves.fastLinearToSlowEaseIn);
});
}
void sendLoginResponse(Client client, bool res) {
final Map<String, dynamic> response = Map();
response["id"] = client.id;
@@ -392,6 +409,7 @@ class ServerModel with ChangeNotifier {
final client = Client.fromJson(jsonDecode(evt['client']));
DialogManager.dismissByTag(getLoginDialogTag(client.id));
_clients[client.id] = client;
scrollToBottom();
notifyListeners();
} catch (e) {}
}