feat: retry logic
Signed-off-by: Kingtous <kingtous@qq.com>
This commit is contained in:
parent
d0e55f6f81
commit
8a3da4eb41
@ -609,6 +609,18 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
return _buildAddressBook(context);
|
return _buildAddressBook(context);
|
||||||
|
} else if (snapshot.hasError) {
|
||||||
|
return Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(translate("${snapshot.error}")),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
child: Text(translate("Retry")))
|
||||||
|
],
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
if (model.abLoading) {
|
if (model.abLoading) {
|
||||||
return Center(
|
return Center(
|
||||||
@ -616,7 +628,17 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
);
|
);
|
||||||
} else if (model.abError.isNotEmpty) {
|
} else if (model.abError.isNotEmpty) {
|
||||||
return Center(
|
return Center(
|
||||||
child: Text(translate("${model.abError}")),
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(translate("${model.abError}")),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
child: Text(translate("Retry")))
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Offstage();
|
return Offstage();
|
||||||
|
@ -24,22 +24,25 @@ class AbModel with ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
// request
|
// request
|
||||||
final api = "${await getApiServer()}/api/ab/get";
|
final api = "${await getApiServer()}/api/ab/get";
|
||||||
final resp = await http.post(Uri.parse(api), headers: await _getHeaders());
|
try {
|
||||||
abLoading = false;
|
final resp =
|
||||||
Map<String, dynamic> json = jsonDecode(resp.body);
|
await http.post(Uri.parse(api), headers: await _getHeaders());
|
||||||
if (json.containsKey('error')) {
|
Map<String, dynamic> json = jsonDecode(resp.body);
|
||||||
abError = json['error'];
|
if (json.containsKey('error')) {
|
||||||
} else if (json.containsKey('data')) {
|
abError = json['error'];
|
||||||
// {"tags":["aaa","bbb"],
|
} else if (json.containsKey('data')) {
|
||||||
// "peers":[{"id":"aa1234","username":"selfd",
|
final data = jsonDecode(json['data']);
|
||||||
// "hostname":"PC","platform":"Windows","tags":["aaa"]}]}
|
tags.value = data['tags'];
|
||||||
final data = jsonDecode(json['data']);
|
peers.value = data['peers'];
|
||||||
tags.value = data['tags'];
|
}
|
||||||
peers.value = data['peers'];
|
return resp.body;
|
||||||
|
} catch (err) {
|
||||||
|
abError = err.toString();
|
||||||
|
} finally {
|
||||||
|
abLoading = false;
|
||||||
}
|
}
|
||||||
print(json);
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
return resp.body;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> getApiServer() async {
|
Future<String> getApiServer() async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user