fix: add null catch on address book request

This commit is contained in:
Kingtous 2022-09-15 11:06:44 +08:00
parent 232c3a1112
commit 088e31d80f
3 changed files with 16 additions and 12 deletions

View File

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

View File

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

View File

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