Merge pull request #1530 from Kingtous/master

fix: add null catch on address book request
This commit is contained in:
RustDesk 2022-09-15 11:18:48 +08:00 committed by GitHub
commit ab60db3e66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 12 deletions

View File

@ -414,7 +414,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
);
} else {
if (model.abLoading) {
return Center(
return const Center(
child: CircularProgressIndicator(),
);
} else if (model.abError.isNotEmpty) {

View File

@ -266,7 +266,7 @@ class AddressBookPeerWidget extends BasePeerWidget {
loadEvent: 'load_address_book_peers',
offstageFunc: (Peer peer) =>
!_hitTag(gFFI.abModel.selectedTags, peer.tags),
peerCardWidgetFunc: (Peer peer) => DiscoveredPeerCard(
peerCardWidgetFunc: (Peer peer) => AddressBookPeerCard(
peer: peer,
),
initPeers: _loadPeers(),

View File

@ -28,21 +28,26 @@ class AbModel with ChangeNotifier {
try {
final resp =
await http.post(Uri.parse(api), headers: await _getHeaders());
Map<String, dynamic> json = jsonDecode(resp.body);
if (json.containsKey('error')) {
abError = json['error'];
} else if (json.containsKey('data')) {
final data = jsonDecode(json['data']);
tags.value = data['tags'];
peers.value = data['peers'];
if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") {
Map<String, dynamic> json = jsonDecode(resp.body);
if (json.containsKey('error')) {
abError = json['error'];
} else if (json.containsKey('data')) {
final data = jsonDecode(json['data']);
tags.value = data['tags'];
peers.value = data['peers'];
}
notifyListeners();
return resp.body;
} else {
return "";
}
return resp.body;
} catch (err) {
abError = err.toString();
} finally {
notifyListeners();
abLoading = false;
}
notifyListeners();
return null;
}
@ -60,7 +65,6 @@ class AbModel with ChangeNotifier {
return _ffi?.getHttpHeaders();
}
///
void addId(String id) async {
if (idContainBy(id)) {
return;