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)),
TextButton(
onPressed: () {
setState(() {});
gFFI.abModel.pullAb();
},
child: Text(translate("Retry")))
],

View File

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

View File

@ -34,15 +34,22 @@ class AbModel {
if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") {
Map<String, dynamic> json = jsonDecode(resp.body);
if (json.containsKey('error')) {
abError = json['error'];
abError.value = json['error'];
} else if (json.containsKey('data')) {
final data = jsonDecode(json['data']);
tags.value = data['tags'];
if (data != null) {
tags.clear();
peers.clear();
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;
} else {
return "";