diff --git a/android/app/build.gradle b/android/app/build.gradle index 00262f3..a321f7c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -136,7 +136,7 @@ dependencies { implementation platform('com.google.firebase:firebase-bom:28.0.1') implementation 'com.google.firebase:firebase-dynamic-links-ktx' // implementation 'com.github.L3-iGrant:mobileSDK-android:2.5.2' - implementation 'com.github.decentralised-dataexchange:bb-consent-android-privacy-dashboard:2023.11.2' + implementation 'com.github.decentralised-dataexchange:bb-consent-android-privacy-dashboard:2023.11.3' implementation 'com.github.zcweng:switch-button:0.0.3@aar' implementation 'com.cocosw:bottomsheet:1.5.0' implementation 'com.github.markomilos:paginate:1.0.0' diff --git a/android/app/src/main/kotlin/io/igrant/data4diabetes/MainActivity.kt b/android/app/src/main/kotlin/io/igrant/data4diabetes/MainActivity.kt index 1adce99..a421cd7 100644 --- a/android/app/src/main/kotlin/io/igrant/data4diabetes/MainActivity.kt +++ b/android/app/src/main/kotlin/io/igrant/data4diabetes/MainActivity.kt @@ -10,6 +10,8 @@ import io.igrant.data_wallet.utils.DataWalletConfigurations import io.igrant.data_wallet.utils.InitializeWalletCallback import io.igrant.data_wallet.utils.InitializeWalletState import io.igrant.data_wallet.utils.dataAgreement.DataAgreementUtils +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch class MainActivity : FlutterActivity() { @@ -66,7 +68,7 @@ class MainActivity : FlutterActivity() { val userId: String?= call.argument("userId") PrivacyDashboard.showPrivacyDashboard().withApiKey(apiKey ?: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsic2VydmljZSJdLCJPcmdhbmlzYXRpb25JZCI6IjY0ZjA5Zjc3OGU1ZjM4MDAwMTRhODc5YSIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2NTBhZTFmYmJlMWViNDAwMDE3MTFkODciLCJleHAiOjE3MzAyMjMyODh9.DlU8DjykYr3eBmbgsKLR4dnaChiRqXdxofKOuk4LiRM") .withUserId(userId ?: "653fe90efec9f34efed23619") - .withOrgId(orgId ?: "64f09f778e5f3800014a879a") + // .withOrgId(orgId ?: "64f09f778e5f3800014a879a") .withBaseUrl(baseUrl ?: "https://demo-consent-bb-api.igrant.io/") // .enableUserRequest() // .enableAskMe() @@ -92,6 +94,28 @@ class MainActivity : FlutterActivity() { val data = DataWallet.queryCredentials(credDefId, schemaId) result.success(data) } + "DataSharing" -> { + val accessToken: String? = call.argument("accessToken") + val dataAgreementID: String? = call.argument("dataAgreementID") + val baseUrl: String? = call.argument("baseUrl") + var data:String? = null + print("access token passes as :$accessToken") + GlobalScope.launch { + data = PrivacyDashboard.optInToDataAgreement( + dataAgreementId = dataAgreementID ?:"", + baseUrl = baseUrl ?: "", + accessToken = accessToken ?: "" + ) + println("response received1:$data"); + if(data !=null){ + result.success(data) + } + else{ + result.error("CUSTOM_ERROR_CODE", "Error occurred. Data: $data", null) + } + + } + } } } diff --git a/lib/app/modules/dataSharing/binding/dataAgreement_binding.dart b/lib/app/modules/dataSharing/binding/dataAgreement_binding.dart new file mode 100644 index 0000000..271b21a --- /dev/null +++ b/lib/app/modules/dataSharing/binding/dataAgreement_binding.dart @@ -0,0 +1,16 @@ + +import 'package:Data4Diabetes/app/modules/dataSharing/controllers/dataAgreement_controller.dart'; +import 'package:get/get.dart'; +import 'package:get/get_instance/src/bindings_interface.dart'; + +class DataAgreementBinding extends Bindings { + @override + void dependencies() { + Get.lazyPut( + () => DataAgreementContoller(), + fenix: true, + ); + + + } +} \ No newline at end of file diff --git a/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart b/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart new file mode 100644 index 0000000..81a425e --- /dev/null +++ b/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart @@ -0,0 +1,206 @@ +import 'dart:convert'; +import 'dart:ui'; + +import 'package:Data4Diabetes/app/core/base/base_controller.dart'; +import 'package:Data4Diabetes/app/modules/Register/controllers/register_controller.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:get/get.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:webview_flutter/webview_flutter.dart'; + +import '../../login/views/login_view.dart'; + +class DataAgreementContoller extends BaseController { + final RegisterController _registerController = Get.find(); + WebViewController? controller; + var platform = const MethodChannel('io.igrant.data4diabetes.channel'); + var dataAgreementId = "654cf0db9684ed907ce07c5"; + + var thirdPartyOrgName = "Data4Diabetes"; + String? accessToken; + var redirectUrl = "https://www.govstack.global/"; + // invokeDataAgreement() { + // controller = WebViewController() + // ..setJavaScriptMode(JavaScriptMode.unrestricted) + // ..setBackgroundColor(const Color(0x00000000)) + // ..setNavigationDelegate( + // NavigationDelegate( + // onProgress: (int progress) { + // // if (progress != maxProgressValue) { + // // showLoading(); + // // } else { + // // hideLoading(); + // // } + // + // return; + // }, + // onPageStarted: (String url) { + // /// show progress on loading + // // showLoading(); + // + // return; + // }, + // onPageFinished: (String url) { + // /// stop progress after loading + // // hideLoading(); + // + // return; + // }, + // onWebResourceError: (WebResourceError error) { + // return; + // }, + // onNavigationRequest: (NavigationRequest request) async { + // if (request.url.startsWith('https://www.govstack.global/')) { + // final uri = Uri.parse(request.url); + // print('the response uri:${uri.queryParameters}'); + // if (uri.queryParameters.containsKey('error')) { + // // Handle error response + // String? error = uri.queryParameters['error']; + // String? errorDescription = uri.queryParameters['errorDescription']; + // print('Error: $error, Description: $errorDescription'); + // GetSnackToast(message: errorDescription??"something went wrong"); + // Get.off(LoginView()); + // } else if (uri.queryParameters.containsKey('credentials')) { + // // Decode the base64-encoded credentials + // print('got scueess data'); + // String? credentialsBase64 = uri.queryParameters['credentials']; + // // Ensure that the base64 string has the correct length and padding + // String paddedCredentialsBase64 = credentialsBase64! + '=' * (4 - credentialsBase64.length % 4); + // + // // Decode the padded base64 string + // List bytes = base64.decode(paddedCredentialsBase64); + // String decodedCredentialsJson = utf8.decode(bytes); + // + // Map decodedCredentials = json.decode(decodedCredentialsJson); + // + // // Accessing user information + // Map userInfo = decodedCredentials['userInfo']; + // String subject = userInfo['subject']; + // String email = userInfo['email']; + // bool emailVerified = userInfo['emailVerified']; + // + // print('Subject: $subject'); + // print('Email: $email'); + // print('Email Verified: $emailVerified'); + // + // // Accessing token information + // Map token = decodedCredentials['token']; + // String accessToken = token['accessToken']; + // int expiresIn = token['expiresIn']; + // String refreshToken = token['refreshToken']; + // + // print('Access Token: $accessToken'); + // print('Expires In: $expiresIn'); + // print('Refresh Token: $refreshToken'); + // + // SharedPreferences _prefs = await SharedPreferences.getInstance(); + // await _prefs.setString('dataSharingAccessToken',accessToken ); + // await _prefs.setInt('dataSharingTokenExpiresIn',expiresIn ); + // await _prefs.setString('dataSharingRefreshToken',refreshToken ); + // Get.back(); + // int index = _registerController.selectedPage.value + 1; + // _registerController.pageController.animateToPage(index, + // duration: const Duration(milliseconds: 500), + // curve: Curves.ease); + // + // + // GetSnackToast(message: 'Authorized successfully',color: Colors.green); + // } + // + // return NavigationDecision.navigate; + // } + // + // return NavigationDecision.navigate; + // }, + // ), + // ) + // ..loadRequest(Uri.parse( + // 'https://staging-consent-bb-iam.igrant.io/realms/3pp-application/protocol/openid-connect/auth?client_id=3pp&response_type=code&redirect_uri=https%3A%2F%2Fstaging-consent-bb-api.igrant.io%2Fv2%2Fservice%2Fdata-sharing%3FdataAgreementId%3D654cf0db9684ed907ce07c5f%26thirdPartyOrgName%3DData4Diabetes%26dataSharingUiRedirectUrl%3Dhttps%3A%2F%2Fwww.govstack.global%2F')); + // } + + invokeDataAgreement() { + controller = WebViewController() + ..setJavaScriptMode(JavaScriptMode.unrestricted) + ..setBackgroundColor(const Color(0x00000000)) + ..setNavigationDelegate( + NavigationDelegate( + onProgress: (int progress) { + return; + }, + onPageStarted: (String url) { + /// show progress on loading + return; + }, + onPageFinished: (String url) { + /// stop progress after loading + return; + }, + onWebResourceError: (WebResourceError error) { + return; + }, + onNavigationRequest: (NavigationRequest request) async { + if (request.url.startsWith(redirectUrl)) { + final uri = Uri.parse(request.url); + if (uri.queryParameters.containsKey('error')) { + // Handle error response + String? error = uri.queryParameters['error']; + String? errorDescription = + uri.queryParameters['errorDescription']; + GetSnackToast( + message: errorDescription ?? "something went wrong"); + Get.off(LoginView()); + _registerController.firstNameController.clear(); + _registerController.mobileNumberController.clear(); + } else if (uri.queryParameters.containsKey('credentials')) { + // Decode the base64-encoded credentials + String? credentialsBase64 = uri.queryParameters['credentials']; + // Ensure that the base64 string has the correct length and padding + String paddedCredentialsBase64 = credentialsBase64! + + '=' * (4 - credentialsBase64.length % 4); + // Decode the padded base64 string + List bytes = base64.decode(paddedCredentialsBase64); + String decodedCredentialsJson = utf8.decode(bytes); + Map decodedCredentials = + json.decode(decodedCredentialsJson); + // Accessing user information + // Map userInfo = decodedCredentials['userInfo']; + // String subject = userInfo['subject']; + // String email = userInfo['email']; + // bool emailVerified = userInfo['emailVerified']; + // Accessing token information + Map token = decodedCredentials['token']; + accessToken = token['accessToken']; + // int expiresIn = token['expiresIn']; + // String refreshToken = token['refreshToken']; + SharedPreferences _prefs = + await SharedPreferences.getInstance(); + await _prefs.setString('dataSharingAccessToken', accessToken!); + var response = await platform.invokeMethod('DataSharing', { + "accessToken": token, + "dataAgreementID": "65530f3507a0b7e06bdd9383", + "baseUrl": "https://staging-consent-bb-api.igrant.io/v2/" + }); + Map responseMap = json.decode(response); + if (responseMap['optIn'] == true) { + Get.back(); + int index = _registerController.selectedPage.value + 1; + _registerController.pageController.animateToPage(index, + duration: const Duration(milliseconds: 500), + curve: Curves.ease); + } else { + GetSnackToast(message: 'something went wrong'); + } + } + + return NavigationDecision.navigate; + } + + return NavigationDecision.navigate; + }, + ), + ) + ..loadRequest(Uri.parse( + 'https://staging-consent-bb-iam.igrant.io/realms/3pp-application/protocol/openid-connect/auth?client_id=3pp&response_type=code&redirect_uri=https%3A%2F%2Fstaging-consent-bb-api.igrant.io%2Fv2%2Fservice%2Fdata-sharing%3FdataAgreementId%3D654cf0db9684ed907ce07c5f%26thirdPartyOrgName%3DData4Diabetes%26dataSharingUiRedirectUrl%3Dhttps%3A%2F%2Fwww.govstack.global%2F')); + } +} diff --git a/lib/app/modules/dataSharing/views/dataAgreement_view.dart b/lib/app/modules/dataSharing/views/dataAgreement_view.dart new file mode 100644 index 0000000..c2d913c --- /dev/null +++ b/lib/app/modules/dataSharing/views/dataAgreement_view.dart @@ -0,0 +1,46 @@ + + +import 'package:Data4Diabetes/app/modules/dataSharing/controllers/dataAgreement_controller.dart'; +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:webview_flutter/webview_flutter.dart'; + +import '../../../Constants/Palette.dart'; +import '../../../core/base/base_view.dart'; + +class DataAgreementView extends BaseView { + @override + PreferredSizeWidget? appBar(BuildContext context) { + return AppBar( + backgroundColor: Colors.transparent, + //centerTitle: true, + elevation: 0, + automaticallyImplyLeading: true, + leading: IconButton( + onPressed: (){ + Get.back(); + }, + icon: const Icon(Icons.arrow_back_ios), + ), + ); + } + final DataAgreementContoller _dataAgreementContoller = Get.find(); + @override + Widget body(BuildContext context) { + return FutureBuilder( + future:_dataAgreementContoller. invokeDataAgreement(), + builder: (BuildContext context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + // Display a loading spinner while waiting for the future to complete + return Center(child: CircularProgressIndicator()); + } else if (snapshot.hasError) { + // Display an error message if the future throws an error + return Text('Error: ${snapshot.error}'); + } else { + // Display the fetched data + return WebViewWidget(controller:_dataAgreementContoller. controller!); + } + }, + ); + } +} \ No newline at end of file diff --git a/lib/app/modules/launcher/bindings/launcher_binding.dart b/lib/app/modules/launcher/bindings/launcher_binding.dart index e76e688..f427589 100644 --- a/lib/app/modules/launcher/bindings/launcher_binding.dart +++ b/lib/app/modules/launcher/bindings/launcher_binding.dart @@ -1,4 +1,5 @@ import 'package:Data4Diabetes/app/modules/Dexcom/controllers/dexcom_controller.dart'; +import 'package:Data4Diabetes/app/modules/dataSharing/controllers/dataAgreement_controller.dart'; import 'package:Data4Diabetes/app/modules/insights/controllers/insights_controller.dart'; import 'package:Data4Diabetes/app/modules/launcher/controller/launcher_controller.dart'; import 'package:Data4Diabetes/app/modules/privacyPolicy/controllers/privacyPolicy_controller.dart'; @@ -83,5 +84,9 @@ class LauncherBinding extends Bindings { () => DexcomCredentailController(), fenix: true, ); + Get.lazyPut( + () => DataAgreementContoller(), + fenix: true, + ); } } diff --git a/lib/app/modules/login/bindings/login_binding.dart b/lib/app/modules/login/bindings/login_binding.dart index c0cd326..8d0422f 100644 --- a/lib/app/modules/login/bindings/login_binding.dart +++ b/lib/app/modules/login/bindings/login_binding.dart @@ -1,6 +1,7 @@ import 'package:Data4Diabetes/app/data/remote/user_remote_data_source.dart'; import 'package:Data4Diabetes/app/modules/Otp/controllers/otp_controller.dart'; import 'package:Data4Diabetes/app/modules/Register/controllers/register_controller.dart'; +import 'package:Data4Diabetes/app/modules/dataSharing/controllers/dataAgreement_controller.dart'; import 'package:Data4Diabetes/app/modules/insights/controllers/insights_controller.dart'; import 'package:Data4Diabetes/app/modules/login/controllers/login_controller.dart'; import 'package:Data4Diabetes/app/modules/privacyPolicy/controllers/privacyPolicy_controller.dart'; @@ -77,5 +78,9 @@ class LoginBinding extends Bindings { () => DexcomCredentailController(), fenix: true, ); + Get.lazyPut( + () => DataAgreementContoller(), + fenix: true, + ); } } diff --git a/lib/app/modules/register/controllers/register_controller.dart b/lib/app/modules/register/controllers/register_controller.dart index 209d105..9bb362c 100644 --- a/lib/app/modules/register/controllers/register_controller.dart +++ b/lib/app/modules/register/controllers/register_controller.dart @@ -1,4 +1,4 @@ -import 'dart:io'; +import 'dart:convert'; import 'package:Data4Diabetes/app/data/model/register/RegisterRequest.dart'; import 'package:Data4Diabetes/app/data/model/register/RegisterResponse.dart'; @@ -6,13 +6,15 @@ import 'package:Data4Diabetes/app/data/model/validateMobileNumber/ValidateMobile import 'package:Data4Diabetes/app/data/model/validateMobileNumber/ValidateMobileNumberResponse.dart'; import 'package:Data4Diabetes/app/data/repository/user_repository_impl.dart'; import 'package:Data4Diabetes/app/modules/Otp/views/otp_view.dart'; -import 'package:Data4Diabetes/app/modules/privacyPolicy/controllers/privacyPolicy_controller.dart'; +import 'package:Data4Diabetes/app/modules/dataSharing/views/dataAgreement_view.dart'; +import 'package:Data4Diabetes/app/modules/login/views/login_view.dart'; import 'package:Data4Diabetes/app/modules/termsOfService/views/termsOfService_view.dart'; import 'package:Data4Diabetes/app/network/exceptions/api_exception.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:intl_phone_number_input/intl_phone_number_input.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import 'package:webview_flutter/webview_flutter.dart'; import '../../login/controllers/login_controller.dart'; import '/app/core/base/base_controller.dart'; @@ -38,8 +40,16 @@ class RegisterController extends BaseController { var shareLastName = "".obs; PhoneNumber number = PhoneNumber(isoCode: 'SE'); String? isdCode; - var validateVisibility=false.obs; - // var circularVisibility=false.obs; + var validateVisibility = false.obs; + + // var circularVisibility=false.obs; + WebViewController? controller; + int maxProgressValue = 100; + var dataAgreementId = "654cf0db9684ed907ce07c5"; + + var thirdPartyOrgName = "Data4Diabetes"; + String? accessToken; + var redirectUrl = "https://www.govstack.global/"; @override void onInit() { pageController = PageController(initialPage: selectedPage.value); @@ -47,130 +57,292 @@ class RegisterController extends BaseController { } void registerUser() async { - showLoading(); - shareFirstName.value = firstNameController.text; - //shareLastName.value = lastNameController.text; - shareLastName.value = ""; - sharePhoneNumber.value = isdCode! + mobileNumberController.text; - RegisterRequest request = RegisterRequest( - firstname: firstNameController.text, - lastname: "no last name", - mobile_number: isdCode! + mobileNumberController.text); + SharedPreferences _prefs = await SharedPreferences.getInstance(); + var token = _prefs.getString('dataSharingAccessToken'); try { - RegisterResponse response = await _impl.register(request); + var response = await platform.invokeMethod('DataSharing', { + "accessToken": token, + "dataAgreementID": "65530f3507a0b7e06bdd9383", + "baseUrl": "https://staging-consent-bb-api.igrant.io/v2/" + }); + Map responseMap = json.decode(response); + if (responseMap['optIn'] == true) { + // Handle success + showLoading(); + shareFirstName.value = firstNameController.text; + //shareLastName.value = lastNameController.text; + shareLastName.value = ""; + sharePhoneNumber.value = isdCode! + mobileNumberController.text; + RegisterRequest request = RegisterRequest( + firstname: firstNameController.text, + lastname: "no last name", + mobile_number: isdCode! + mobileNumberController.text); + try { + RegisterResponse response = await _impl.register(request); - if (response.msg == "OTP sent") { - hideLoading(); - loginController.isControl.value = false; - Get.off(OtpView()); - firstNameController.clear(); - //lastNameController.clear(); - mobileNumberController.clear(); + if (response.msg == "OTP sent") { + hideLoading(); + loginController.isControl.value = false; + Get.off(OtpView()); + firstNameController.clear(); + mobileNumberController.clear(); + } + } catch (e) { + firstNameController.clear(); + mobileNumberController.clear(); + GetSnackToast(message: (e as ApiException).message); + + hideLoading(); + } finally { + hideLoading(); + } + } else { + GetSnackToast(message: 'Something went wrong'); } } catch (e) { - firstNameController.clear(); - //lastNameController.clear(); - mobileNumberController.clear(); - GetSnackToast(message: (e as ApiException).message); - - hideLoading(); - } finally { - hideLoading(); + GetSnackToast(message: e.toString()); } } void showDataAgreement() { // if (Platform.isAndroid) { - switch (selectedIndex.value) { - case 0: - { - platform.invokeMethod('DataAgreementPolicy', { - "ApiKey": - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI2NDVhNDE0YmI5YjA1NTAwMDE1MGIyNDciLCJvcmdpZCI6IiIsImVudiI6IiIsImV4cCI6MTcxNDc0MDg4Nn0.u6pBpv12ZfdHYMPoQHYR-oBR9ZOZVeHiChaQ8yiEMxE', - "orgId": '645a4172b9b055000150b248', - "dataAgreementId": '0900ccb0-73d5-4175-ae79-a3fc14a14e9e' - }); - } - break; - - case 1: - { - platform.invokeMethod('DataAgreementPolicy', { - "ApiKey": - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI2NDVhNDE0YmI5YjA1NTAwMDE1MGIyNDciLCJvcmdpZCI6IiIsImVudiI6IiIsImV4cCI6MTcxNDc0MDg4Nn0.u6pBpv12ZfdHYMPoQHYR-oBR9ZOZVeHiChaQ8yiEMxE', - "orgId": '645a4172b9b055000150b248', - "dataAgreementId": '43bbd177-a6bf-4e97-a771-4f77fca4960e' - }); - } - break; - case 2: - { - platform.invokeMethod('DataAgreementPolicy', { - "ApiKey": - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI2NDVhNDE0YmI5YjA1NTAwMDE1MGIyNDciLCJvcmdpZCI6IiIsImVudiI6IiIsImV4cCI6MTcxNDc0MDg4Nn0.u6pBpv12ZfdHYMPoQHYR-oBR9ZOZVeHiChaQ8yiEMxE', - "orgId": '645a4172b9b055000150b248', - "dataAgreementId": '6759b7ba-e12e-4ff8-915b-598a759c77d0' - }); - } - break; - default: - break; - } + switch (selectedIndex.value) { + case 0: + { + platform.invokeMethod('DataAgreementPolicy', { + "ApiKey": + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI2NDVhNDE0YmI5YjA1NTAwMDE1MGIyNDciLCJvcmdpZCI6IiIsImVudiI6IiIsImV4cCI6MTcxNDc0MDg4Nn0.u6pBpv12ZfdHYMPoQHYR-oBR9ZOZVeHiChaQ8yiEMxE', + "orgId": '645a4172b9b055000150b248', + "dataAgreementId": '0900ccb0-73d5-4175-ae79-a3fc14a14e9e' + }); + } + break; + + case 1: + { + platform.invokeMethod('DataAgreementPolicy', { + "ApiKey": + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI2NDVhNDE0YmI5YjA1NTAwMDE1MGIyNDciLCJvcmdpZCI6IiIsImVudiI6IiIsImV4cCI6MTcxNDc0MDg4Nn0.u6pBpv12ZfdHYMPoQHYR-oBR9ZOZVeHiChaQ8yiEMxE', + "orgId": '645a4172b9b055000150b248', + "dataAgreementId": '43bbd177-a6bf-4e97-a771-4f77fca4960e' + }); + } + break; + case 2: + { + platform.invokeMethod('DataAgreementPolicy', { + "ApiKey": + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI2NDVhNDE0YmI5YjA1NTAwMDE1MGIyNDciLCJvcmdpZCI6IiIsImVudiI6IiIsImV4cCI6MTcxNDc0MDg4Nn0.u6pBpv12ZfdHYMPoQHYR-oBR9ZOZVeHiChaQ8yiEMxE', + "orgId": '645a4172b9b055000150b248', + "dataAgreementId": '6759b7ba-e12e-4ff8-915b-598a759c77d0' + }); + } + break; + default: + break; + } // } else if (Platform.isIOS) { // showToast('Coming soon'); // } } - void termsOfServices(){ + + void termsOfServices() { Get.to(TermsOfServiceView()); } - validateMobileNumber() async { - ValidateMobileNumberRequest request = - ValidateMobileNumberRequest(mobile_number: isdCode! + mobileNumberController.text); + + validateMobileNumber() async { + ValidateMobileNumberRequest request = ValidateMobileNumberRequest( + mobile_number: isdCode! + mobileNumberController.text); try { - ValidateMobileNumberResponse response = await _impl.validateMobileNumber(request); - if (response.isValidMobileNumber ==true) { + ValidateMobileNumberResponse response = + await _impl.validateMobileNumber(request); + if (response.isValidMobileNumber == true) { hideLoading(); - validateVisibility.value=true; - // circularVisibility.value=false; - } - else if(response.isValidMobileNumber==false){ - - validateVisibility.value=false; - + validateVisibility.value = true; + // circularVisibility.value=false; + } else if (response.isValidMobileNumber == false) { + validateVisibility.value = false; } } catch (e) { // showToast((e as ApiException).message); GetSnackToast(message: (e as ApiException).message); hideLoading(); - } - finally{ + } finally { hideLoading(); } } - void onNextButtonTap(){ + Future onNextButtonTap() async { String pattern = r'(^(?:[+0]9)?[0-9]{10,12}$)'; RegExp regExp = RegExp(pattern); - if(firstNameController.text==""){ + if (firstNameController.text == "") { GetSnackToast(message: appLocalization.registerFirstNameValidationText); - } - else if(mobileNumberController.text==""){ - + } else if (mobileNumberController.text == "") { GetSnackToast(message: appLocalization.registerPhoneNumberValidationText); + } else if (!regExp.hasMatch(mobileNumberController.text)) { + GetSnackToast( + message: appLocalization.registerValidPhoneNumberValidationText); + } else if (validateVisibility.value == true) { + GetSnackToast( + message: appLocalization.registerExistingUser, + ); + } else { + Get.to(DataAgreementView()); + // int index = selectedPage.value + 1; + // pageController.animateToPage(index, + // duration: const Duration(milliseconds: 500), + // curve: Curves.ease); + //} } - else if(!regExp.hasMatch(mobileNumberController.text)){ - GetSnackToast(message: appLocalization.registerValidPhoneNumberValidationText); - } else if(validateVisibility.value==true){ - GetSnackToast(message: appLocalization.registerExistingUser,); - } - else{ - int index = selectedPage.value + 1; - pageController.animateToPage(index, + } + + // invokeDataAgreement() { + // controller = WebViewController() + // ..setJavaScriptMode(JavaScriptMode.unrestricted) + // ..setBackgroundColor(const Color(0x00000000)) + // ..setNavigationDelegate( + // NavigationDelegate( + // onProgress: (int progress) { + // return; + // }, + // onPageStarted: (String url) { + // /// show progress on loading + // return; + // }, + // onPageFinished: (String url) { + // /// stop progress after loading + // return; + // }, + // onWebResourceError: (WebResourceError error) { + // return; + // }, + // onNavigationRequest: (NavigationRequest request) async { + // if (request.url.startsWith(redirectUrl)) { + // final uri = Uri.parse(request.url); + // if (uri.queryParameters.containsKey('error')) { + // // Handle error response + // String? error = uri.queryParameters['error']; + // String? errorDescription = + // uri.queryParameters['errorDescription']; + // GetSnackToast( + // message: errorDescription ?? "something went wrong"); + // Get.off(LoginView()); + // } else if (uri.queryParameters.containsKey('credentials')) { + // // Decode the base64-encoded credentials + // String? credentialsBase64 = uri.queryParameters['credentials']; + // // Ensure that the base64 string has the correct length and padding + // String paddedCredentialsBase64 = credentialsBase64! + + // '=' * (4 - credentialsBase64.length % 4); + // // Decode the padded base64 string + // List bytes = base64.decode(paddedCredentialsBase64); + // String decodedCredentialsJson = utf8.decode(bytes); + // Map decodedCredentials = + // json.decode(decodedCredentialsJson); + // // Accessing user information + // Map userInfo = decodedCredentials['userInfo']; + // String subject = userInfo['subject']; + // String email = userInfo['email']; + // bool emailVerified = userInfo['emailVerified']; + // // Accessing token information + // Map token = decodedCredentials['token']; + // accessToken = token['accessToken']; + // int expiresIn = token['expiresIn']; + // String refreshToken = token['refreshToken']; + // SharedPreferences _prefs = + // await SharedPreferences.getInstance(); + // await _prefs.setString('dataSharingAccessToken', accessToken!); + // Get.back(); + // + // int index = selectedPage.value + 1; + // pageController.animateToPage(index, + // duration: const Duration(milliseconds: 500), + // curve: Curves.ease); + // + // } + // + // return NavigationDecision.navigate; + // } + // + // return NavigationDecision.navigate; + // }, + // ), + // ) + // ..loadRequest(Uri.parse( + // 'https://staging-consent-bb-iam.igrant.io/realms/3pp-application/protocol/openid-connect/auth?client_id=3pp&response_type=code&redirect_uri=https%3A%2F%2Fstaging-consent-bb-api.igrant.io%2Fv2%2Fservice%2Fdata-sharing%3FdataAgreementId%3D$dataAgreementId%26thirdPartyOrgName%3DData4Diabetes%26dataSharingUiRedirectUrl%3Dhttps%3A%2F%2Fwww.govstack.global%2F')); + // } + + // void _dataAgreementPopUPWidget() async { + // // Display the WebView in a pop-up dialog + // final context = Get.context; + // if (context != null){ + // await showDialog( + // context: Get.context!, + // builder: (BuildContext context) { + // return AlertDialog( + // content: SizedBox( + // width: double.infinity, + // height: MediaQuery.of(context).size.height, + // child: FutureBuilder( + // future: invokeDataAgreement(), + // builder: (BuildContext context, snapshot) { + // if (snapshot.connectionState == ConnectionState.waiting) { + // // Display a loading spinner while waiting for the future to complete + // return Center(child: CircularProgressIndicator()); + // } else if (snapshot.hasError) { + // // Display an error message if the future throws an error + // return Text('Error: ${snapshot.error}'); + // } else { + // // Display the fetched data using WebView + // return FutureBuilder( + // future: invokeDataAgreement(), + // builder: (BuildContext context, snapshot) { + // if (snapshot.connectionState == ConnectionState.waiting) { + // // Display a loading spinner while waiting for the future to complete + // return Center(child: CircularProgressIndicator()); + // } else if (snapshot.hasError) { + // // Display an error message if the future throws an error + // return Text('Error: ${snapshot.error}'); + // } else { + // // Display the fetched data + // return WebViewWidget(controller:controller!); + // } + // }, + // ); + // } + // }, + // ), + // ), + // ); + // }, + // ); + // } + // + // } + onAgreeButtonTap() async { + SharedPreferences _prefs = await SharedPreferences.getInstance(); + var token = _prefs.getString('dataSharingAccessToken'); + try { + var response = await platform.invokeMethod('DataSharing', { + "accessToken": token, + "dataAgreementID": "65530f3507a0b7e06bdd9383", + "baseUrl": "https://staging-consent-bb-api.igrant.io/v2/" + }); + Map responseMap = json.decode(response); + if (responseMap['optIn'] == true) { + // Handle success + int index = selectedPage.value + 1; + pageController.animateToPage( + index, duration: const Duration(milliseconds: 500), - curve: Curves.ease); + curve: Curves.ease, + ); + } else { + GetSnackToast(message: 'Something went wrong'); + } + } catch (e) { + GetSnackToast(message: e.toString()); } - } } diff --git a/lib/app/modules/register/views/register_view.dart b/lib/app/modules/register/views/register_view.dart index 3955a20..2c6b284 100644 --- a/lib/app/modules/register/views/register_view.dart +++ b/lib/app/modules/register/views/register_view.dart @@ -323,6 +323,7 @@ class RegisterView extends BaseView { ), ), onPressed: () { + FocusScope.of(context).unfocus(); _registerController.onNextButtonTap(); }, child: Padding( @@ -364,9 +365,7 @@ class RegisterView extends BaseView { ), ), onPressed: () { - int index = _registerController.selectedPage.value + 1; - _registerController.pageController.animateToPage(index, - duration: const Duration(milliseconds: 500), curve: Curves.ease); + _registerController.onAgreeButtonTap(); }, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10), diff --git a/lib/app/routes/app_pages.dart b/lib/app/routes/app_pages.dart index ad66a13..51e8c85 100644 --- a/lib/app/routes/app_pages.dart +++ b/lib/app/routes/app_pages.dart @@ -4,6 +4,8 @@ import 'package:Data4Diabetes/app/modules/Otp/bindings/otp_binding.dart'; import 'package:Data4Diabetes/app/modules/Otp/views/otp_view.dart'; import 'package:Data4Diabetes/app/modules/Register/bindings/register_binding.dart'; import 'package:Data4Diabetes/app/modules/Register/views/register_view.dart'; +import 'package:Data4Diabetes/app/modules/dataSharing/binding/dataAgreement_binding.dart'; +import 'package:Data4Diabetes/app/modules/dataSharing/views/dataAgreement_view.dart'; import 'package:Data4Diabetes/app/modules/insights/bindings/insights_binding.dart'; import 'package:Data4Diabetes/app/modules/insights/views/insights_view.dart'; import 'package:Data4Diabetes/app/modules/language/bindings/language_binding.dart'; @@ -121,5 +123,10 @@ class AppPages { page: () => DexcomCredentialView(), binding: DexcomCredentialsBinding(), ), + GetPage( + name: _Paths.DATAAGREEMENT, + page: () => DataAgreementView(), + binding: DataAgreementBinding(), + ), ]; } diff --git a/lib/app/routes/app_routes.dart b/lib/app/routes/app_routes.dart index fd36fa9..99437a4 100644 --- a/lib/app/routes/app_routes.dart +++ b/lib/app/routes/app_routes.dart @@ -19,6 +19,7 @@ abstract class Routes { static const CREDENTIALSPANEL = _Paths.CREDENTIALSPANEL; static const PRIVACYDASHBOARDCREDENTIAL = _Paths.PRIVACYDASHBOARDCREDENTIAL; static const DEXCOMCREDENTIAL = _Paths.DEXCOMCREDENTIAL; + static const DATAAGREEMENT = _Paths.DATAAGREEMENT; } abstract class _Paths { @@ -38,4 +39,5 @@ abstract class _Paths { static const CREDENTIALSPANEL = '/credentialsPanel'; static const PRIVACYDASHBOARDCREDENTIAL = '/credentialsPanel'; static const DEXCOMCREDENTIAL = '/credentialsPanel'; + static const DATAAGREEMENT = '/dataAgreement'; } diff --git a/pubspec.yaml b/pubspec.yaml index 74e01e5..0d96857 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,7 +30,7 @@ dependencies: package_info_plus: ^3.1.0 intl_phone_number_input: ^0.7.3+1 sms_autofill: ^2.3.0 - webview_flutter: ^4.2.0 + webview_flutter: ^4.4.2 http: ^0.13.6 page_view_dot_indicator: ^2.1.0 dropdown_button2: ^2.1.0