android ensure clients sync;new client scrollToBottom
This commit is contained in:
parent
11a1b12fe7
commit
59e7d53e7d
@ -41,6 +41,8 @@ class ServerModel with ChangeNotifier {
|
|||||||
|
|
||||||
Map<int, Client> get clients => _clients;
|
Map<int, Client> get clients => _clients;
|
||||||
|
|
||||||
|
final controller = ScrollController();
|
||||||
|
|
||||||
ServerModel() {
|
ServerModel() {
|
||||||
() async {
|
() async {
|
||||||
/**
|
/**
|
||||||
@ -95,6 +97,12 @@ class ServerModel with ChangeNotifier {
|
|||||||
_connectStatus = status;
|
_connectStatus = status;
|
||||||
notifyListeners();
|
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();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateClientState() {
|
updateClientState([String? json]) {
|
||||||
var res = FFI.getByName("clients_state");
|
var res = json ?? FFI.getByName("clients_state");
|
||||||
try {
|
try {
|
||||||
final List clientsJson = jsonDecode(res);
|
final List clientsJson = jsonDecode(res);
|
||||||
for (var clientJson in clientsJson) {
|
for (var clientJson in clientsJson) {
|
||||||
@ -315,6 +323,7 @@ class ServerModel with ChangeNotifier {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_clients[client.id] = client;
|
_clients[client.id] = client;
|
||||||
|
scrollToBottom();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
showLoginDialog(client);
|
showLoginDialog(client);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -368,6 +377,14 @@ class ServerModel with ChangeNotifier {
|
|||||||
tag: getLoginDialogTag(client.id));
|
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) {
|
void sendLoginResponse(Client client, bool res) {
|
||||||
final Map<String, dynamic> response = Map();
|
final Map<String, dynamic> response = Map();
|
||||||
response["id"] = client.id;
|
response["id"] = client.id;
|
||||||
@ -392,6 +409,7 @@ class ServerModel with ChangeNotifier {
|
|||||||
final client = Client.fromJson(jsonDecode(evt['client']));
|
final client = Client.fromJson(jsonDecode(evt['client']));
|
||||||
DialogManager.dismissByTag(getLoginDialogTag(client.id));
|
DialogManager.dismissByTag(getLoginDialogTag(client.id));
|
||||||
_clients[client.id] = client;
|
_clients[client.id] = client;
|
||||||
|
scrollToBottom();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ class ServerPage extends StatelessWidget implements PageShape {
|
|||||||
value: FFI.serverModel,
|
value: FFI.serverModel,
|
||||||
child: Consumer<ServerModel>(
|
child: Consumer<ServerModel>(
|
||||||
builder: (context, serverModel, child) => SingleChildScrollView(
|
builder: (context, serverModel, child) => SingleChildScrollView(
|
||||||
|
controller: FFI.serverModel.controller,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
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"),
|
translate("android_new_connection_tip"),
|
||||||
style: TextStyle(color: Colors.black54),
|
style: TextStyle(color: Colors.black54),
|
||||||
),
|
),
|
||||||
entry.value.authorized? ElevatedButton.icon(
|
entry.value.authorized
|
||||||
|
? ElevatedButton.icon(
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
MaterialStateProperty.all(Colors.red)),
|
MaterialStateProperty.all(Colors.red)),
|
||||||
icon: Icon(Icons.close),
|
icon: Icon(Icons.close),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
FFI.setByName("close_conn", entry.key.toString());
|
FFI.setByName("close_conn", entry.key.toString());
|
||||||
FFI.invokeMethod("cancel_notification", entry.key);
|
FFI.invokeMethod(
|
||||||
|
"cancel_notification", entry.key);
|
||||||
},
|
},
|
||||||
label: Text(translate("Close"))):
|
label: Text(translate("Close")))
|
||||||
Row(children: [
|
: Row(children: [
|
||||||
TextButton(
|
TextButton(
|
||||||
child: Text(translate("Dismiss")),
|
child: Text(translate("Dismiss")),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
serverModel.sendLoginResponse(entry.value,false);
|
serverModel.sendLoginResponse(
|
||||||
|
entry.value, false);
|
||||||
}),
|
}),
|
||||||
SizedBox(width: 20),
|
SizedBox(width: 20),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
child: Text(translate("Accept")),
|
child: Text(translate("Accept")),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
serverModel.sendLoginResponse(entry.value,true);
|
serverModel.sendLoginResponse(
|
||||||
|
entry.value, true);
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user