mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 15:54:35 +01:00
fix: cant sort servers order (#930)
This commit is contained in:
@@ -239,6 +239,50 @@ class ServersNotifier extends _$ServersNotifier {
|
||||
bakSync.sync(milliDelay: 1000);
|
||||
}
|
||||
|
||||
void updateServerOrder(List<String> order) {
|
||||
final seen = <String>{};
|
||||
final newOrder = <String>[];
|
||||
|
||||
for (final id in order) {
|
||||
if (!state.servers.containsKey(id)) {
|
||||
continue;
|
||||
}
|
||||
if (!seen.add(id)) {
|
||||
continue;
|
||||
}
|
||||
newOrder.add(id);
|
||||
}
|
||||
|
||||
for (final id in state.servers.keys) {
|
||||
if (seen.add(id)) {
|
||||
newOrder.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (_isSameOrder(newOrder, state.serverOrder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
state = state.copyWith(serverOrder: newOrder);
|
||||
Stores.setting.serverOrder.put(newOrder);
|
||||
bakSync.sync(milliDelay: 1000);
|
||||
}
|
||||
|
||||
bool _isSameOrder(List<String> a, List<String> b) {
|
||||
if (identical(a, b)) {
|
||||
return true;
|
||||
}
|
||||
if (a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
if (a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> updateServer(Spi old, Spi newSpi) async {
|
||||
if (old != newSpi) {
|
||||
Stores.server.update(old, newSpi);
|
||||
|
||||
@@ -41,7 +41,7 @@ final class ServersNotifierProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$serversNotifierHash() => r'2b29ad3027a203c7a20bfd0142d384a503cbbcaa';
|
||||
String _$serversNotifierHash() => r'3292bdce7d602ff64687b05ff81d120e71761ec2';
|
||||
|
||||
abstract class _$ServersNotifier extends $Notifier<ServersState> {
|
||||
ServersState build();
|
||||
|
||||
@@ -58,7 +58,7 @@ final class ServerNotifierProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$serverNotifierHash() => r'd9724fbe6d132f2e2ea4dfa5af73aeab168e1c57';
|
||||
String _$serverNotifierHash() => r'185c6b4546c3bc526f5b2ca79d16aed665818863';
|
||||
|
||||
final class ServerNotifierFamily extends $Family
|
||||
with
|
||||
|
||||
Reference in New Issue
Block a user