From 46ba11cd573061055a4ce9bb6cc1c0ffdaa70a3a Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Wed, 22 May 2024 00:49:51 +0300 Subject: [PATCH] Fix: connection problems checks --- lib/mobile_example.dart | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/mobile_example.dart b/lib/mobile_example.dart index ead8372..ac18d73 100644 --- a/lib/mobile_example.dart +++ b/lib/mobile_example.dart @@ -108,15 +108,19 @@ class _ExamplePageState extends State { Future _getToken() async { var url = Uri.http('gymlink.freemyip.com:8080', 'api/auth/authorize_client'); - var response = await http.post(url, body: { - 'GymKey': 'eeb42dcb-8e5b-4f21-825a-3fc7ada43445', - 'id': '123' - }); // Just testing token - var decodedBody = jsonDecode(response.body) as Map; - if (decodedBody['payload'] == null) { + try { + var response = await http.post(url, body: { + 'GymKey': 'eeb42dcb-8e5b-4f21-825a-3fc7ada43445', + 'id': '123' + }); // Just testing token + var decodedBody = jsonDecode(response.body) as Map; + if (decodedBody['payload'] == null) { + return ''; + } + return decodedBody['payload']['token']; + } catch (e) { return ''; } - return decodedBody['payload']['token']; } @override