2021-04-20 23:54:47 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class ServerListState extends ChangeNotifier {
|
|
|
|
List<ServerInfoState> _servers = [];
|
|
|
|
|
|
|
|
void replace(Iterable<ServerInfoState> newServers) {
|
|
|
|
_servers.clear();
|
|
|
|
_servers.addAll(newServers);
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2021-05-28 21:48:55 +00:00
|
|
|
ServerInfoState? getServer(String onion) {
|
2021-04-20 23:54:47 +00:00
|
|
|
int idx = _servers.indexWhere((element) => element.onion == onion);
|
2021-05-28 21:48:55 +00:00
|
|
|
return idx >= 0 ? _servers[idx] : null;
|
2021-04-20 23:54:47 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 19:33:19 +00:00
|
|
|
void updateServerCache(String onion, String status) {
|
|
|
|
int idx = _servers.indexWhere((element) => element.onion == onion);
|
|
|
|
if (idx >= 0) {
|
|
|
|
_servers[idx] = ServerInfoState(onion: onion, status: status);
|
|
|
|
} else {
|
|
|
|
print("Tried to update server cache without a starting state...this is probably an error");
|
|
|
|
}
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2021-04-20 23:54:47 +00:00
|
|
|
List<ServerInfoState> get servers => _servers.sublist(0); //todo: copy?? dont want caller able to bypass changenotifier
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ServerInfoState extends ChangeNotifier {
|
|
|
|
final String onion;
|
|
|
|
final String status;
|
|
|
|
|
2021-05-25 00:11:39 +00:00
|
|
|
ServerInfoState({required this.onion, required this.status});
|
2021-04-20 23:54:47 +00:00
|
|
|
}
|