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) {}
}

View File

@ -65,6 +65,7 @@ class ServerPage extends StatelessWidget implements PageShape {
value: FFI.serverModel,
child: Consumer<ServerModel>(
builder: (context, serverModel, child) => SingleChildScrollView(
controller: FFI.serverModel.controller,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
@ -336,31 +337,37 @@ class ConnectionManager extends StatelessWidget {
))
],
),
entry.value.authorized?SizedBox.shrink():Text(
entry.value.authorized
? SizedBox.shrink()
: Text(
translate("android_new_connection_tip"),
style: TextStyle(color: Colors.black54),
),
entry.value.authorized? ElevatedButton.icon(
entry.value.authorized
? ElevatedButton.icon(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.red)),
icon: Icon(Icons.close),
onPressed: () {
FFI.setByName("close_conn", entry.key.toString());
FFI.invokeMethod("cancel_notification", entry.key);
FFI.invokeMethod(
"cancel_notification", entry.key);
},
label: Text(translate("Close"))):
Row(children: [
label: Text(translate("Close")))
: Row(children: [
TextButton(
child: Text(translate("Dismiss")),
onPressed: () {
serverModel.sendLoginResponse(entry.value,false);
serverModel.sendLoginResponse(
entry.value, false);
}),
SizedBox(width: 20),
ElevatedButton(
child: Text(translate("Accept")),
onPressed: () {
serverModel.sendLoginResponse(entry.value,true);
serverModel.sendLoginResponse(
entry.value, true);
}),
]),
],