From a524ebb525c36599b74110b1f87c0c72bc0c3dc3 Mon Sep 17 00:00:00 2001 From: Lijo George Date: Wed, 15 Nov 2023 12:36:14 +0530 Subject: [PATCH] #193 show loader show loader while calling SDKs --- .../controllers/dataAgreement_controller.dart | 8 +++- .../controllers/register_controller.dart | 39 +++++++------------ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart b/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart index cab8fd4..7b3e1f8 100644 --- a/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart +++ b/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart @@ -20,7 +20,6 @@ class DataAgreementContoller extends BaseController { var thirdPartyOrgName = "Data4Diabetes"; String? accessToken; var redirectUrl = "https://www.govstack.global/"; - invokeDataAgreement() { controller = WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) @@ -32,10 +31,14 @@ class DataAgreementContoller extends BaseController { }, onPageStarted: (String url) { /// show progress on loading + showLoading(); + return; }, onPageFinished: (String url) { /// stop progress after loading + hideLoading(); + return; }, onWebResourceError: (WebResourceError error) { @@ -72,6 +75,7 @@ class DataAgreementContoller extends BaseController { await _prefs.setString('dataSharingAccessToken', accessToken!); var userId = _prefs.getString('privacyDashboarduserId'); try { + showLoading(); var response = await platform.invokeMethod('DataSharing', { "apiKey": PrivacyDashboard().apiKey, "userId": userId??PrivacyDashboard().userId, @@ -89,7 +93,9 @@ class DataAgreementContoller extends BaseController { } else { GetSnackToast(message: 'something went wrong'); } + hideLoading(); } catch (e) { + hideLoading(); GetSnackToast(message: e.toString()); } } diff --git a/lib/app/modules/register/controllers/register_controller.dart b/lib/app/modules/register/controllers/register_controller.dart index bf7a626..34e4dc4 100644 --- a/lib/app/modules/register/controllers/register_controller.dart +++ b/lib/app/modules/register/controllers/register_controller.dart @@ -58,7 +58,7 @@ class RegisterController extends BaseController { pageController = PageController(initialPage: selectedPage.value); super.onInit(); } - + void registerUser() async { try { SharedPreferences _prefs = await SharedPreferences.getInstance(); @@ -177,11 +177,13 @@ class RegisterController extends BaseController { onSkipTap() async { try { + showLoading(); getDataAgreement( sharingtoken: accessToken, sharingDataAgreementID: PrivacyDashboard().backupAndRestoreDataAgreementId, isFlag: true); + hideLoading(); // Handle success int index = selectedPage.value + 1; pageController.animateToPage( @@ -190,6 +192,7 @@ class RegisterController extends BaseController { curve: Curves.ease, ); } catch (e) { + hideLoading(); GetSnackToast(message: e.toString()); } } @@ -348,6 +351,7 @@ class RegisterController extends BaseController { // } onAgreeButtonTap() async { try { + showLoading(); SharedPreferences _prefs = await SharedPreferences.getInstance(); var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('DataSharing', { @@ -373,7 +377,9 @@ class RegisterController extends BaseController { } else { GetSnackToast(message: 'Something went wrong'); } + hideLoading(); } catch (e) { + hideLoading(); GetSnackToast(message: e.toString()); } } @@ -383,6 +389,7 @@ class RegisterController extends BaseController { required String? sharingDataAgreementID, bool? isFlag}) async { try { + showLoading(); SharedPreferences _prefs = await SharedPreferences.getInstance(); var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('GetDataAgreement', { @@ -394,7 +401,7 @@ class RegisterController extends BaseController { Map responseMap = json.decode(response); print('response map: $responseMap'); - + hideLoading(); // call ShowDataAgreementPolicy if (isFlag != true) { await platform.invokeMethod('ShowDataAgreementPolicy', { @@ -420,13 +427,16 @@ class RegisterController extends BaseController { print('dataAttributes values ${dataAttributes[0]}'); } } + } catch (e) { + hideLoading(); GetSnackToast(message: e.toString()); } } getDataAgreementWithApiKey({required String? sharingDataAgreementID}) async { try { + showLoading(); SharedPreferences _prefs = await SharedPreferences.getInstance(); var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('GetDataAgreementWithApiKey', { @@ -438,34 +448,15 @@ class RegisterController extends BaseController { Map responseMap = json.decode(response); print('response map: $responseMap'); - + hideLoading(); // call ShowDataAgreementPolicy await platform.invokeMethod('ShowDataAgreementPolicy', { "dataAgreementResponse": response, }); - - // // Check if "dataAttributes" is not empty - // if (responseMap.containsKey("dataAttributes") && - // responseMap["dataAttributes"] is List && - // responseMap["dataAttributes"].isNotEmpty) { - // - // // Clear the existing dataAttributes list - // dataAttributes.clear(); - // - // // Iterate through the response dataAttributes and add them to the list - // for (var attribute in responseMap["dataAttributes"]) { - // String nameValue = attribute["name"]; - // dataAttributes.add(nameValue); - // - // } - // - // // Print the first item in the dataAttributes list - // if (dataAttributes.isNotEmpty) { - // print('dataAttributes values ${dataAttributes[0]}'); - // } - // } + // hideLoading(); } catch (e) { + hideLoading(); GetSnackToast(message: e.toString()); } }