Skip to content

Commit

Permalink
#193 show loader
Browse files Browse the repository at this point in the history
show loader while calling SDKs
  • Loading branch information
lijogeorgep authored and josmilan committed Nov 15, 2023
1 parent 48add2b commit a524ebb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -89,7 +93,9 @@ class DataAgreementContoller extends BaseController {
} else {
GetSnackToast(message: 'something went wrong');
}
hideLoading();
} catch (e) {
hideLoading();
GetSnackToast(message: e.toString());
}
}
Expand Down
39 changes: 15 additions & 24 deletions lib/app/modules/register/controllers/register_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RegisterController extends BaseController {
pageController = PageController(initialPage: selectedPage.value);
super.onInit();
}

void registerUser() async {
try {
SharedPreferences _prefs = await SharedPreferences.getInstance();
Expand Down Expand Up @@ -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(
Expand All @@ -190,6 +192,7 @@ class RegisterController extends BaseController {
curve: Curves.ease,
);
} catch (e) {
hideLoading();
GetSnackToast(message: e.toString());
}
}
Expand Down Expand Up @@ -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', {
Expand All @@ -373,7 +377,9 @@ class RegisterController extends BaseController {
} else {
GetSnackToast(message: 'Something went wrong');
}
hideLoading();
} catch (e) {
hideLoading();
GetSnackToast(message: e.toString());
}
}
Expand All @@ -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', {
Expand All @@ -394,7 +401,7 @@ class RegisterController extends BaseController {

Map<String, dynamic> responseMap = json.decode(response);
print('response map: $responseMap');

hideLoading();
// call ShowDataAgreementPolicy
if (isFlag != true) {
await platform.invokeMethod('ShowDataAgreementPolicy', {
Expand All @@ -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', {
Expand All @@ -438,34 +448,15 @@ class RegisterController extends BaseController {

Map<String, dynamic> 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());
}
}
Expand Down

0 comments on commit a524ebb

Please sign in to comment.