judge attribute when parse ab json

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2022-11-30 11:13:02 +08:00
parent 5a7f610b59
commit 9788f3684f
3 changed files with 16 additions and 10 deletions

View File

@ -90,7 +90,7 @@ class _AddressBookState extends State<AddressBook> {
Text(translate(error)), Text(translate(error)),
TextButton( TextButton(
onPressed: () { onPressed: () {
setState(() {}); gFFI.abModel.pullAb();
}, },
child: Text(translate("Retry"))) child: Text(translate("Retry")))
], ],

View File

@ -113,7 +113,7 @@ class _ConnectionPageState extends State<ConnectionPage>
delegate: SliverChildListDelegate([ delegate: SliverChildListDelegate([
Row( Row(
children: [ children: [
_buildRemoteIDTextField(context), Flexible(child: _buildRemoteIDTextField(context)),
], ],
).marginOnly(top: 22), ).marginOnly(top: 22),
SizedBox(height: 12), SizedBox(height: 12),
@ -237,9 +237,8 @@ class _ConnectionPageState extends State<ConnectionPage>
), ),
), ),
); );
return Center( return Container(
child: Container( constraints: const BoxConstraints(maxWidth: 600), child: w);
constraints: const BoxConstraints(maxWidth: 600), child: w));
} }
Widget buildStatus() { Widget buildStatus() {

View File

@ -34,13 +34,20 @@ class AbModel {
if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") { 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.value = json['error'];
} else if (json.containsKey('data')) { } else if (json.containsKey('data')) {
final data = jsonDecode(json['data']); final data = jsonDecode(json['data']);
tags.value = data['tags']; if (data != null) {
peers.clear(); tags.clear();
for (final peer in data['peers']) { peers.clear();
peers.add(Peer.fromJson(peer)); if (data['tags'] is List) {
tags.value = data['tags'];
}
if (data['peers'] is List) {
for (final peer in data['peers']) {
peers.add(Peer.fromJson(peer));
}
}
} }
} }
return resp.body; return resp.body;