Skip to content

Commit

Permalink
#156 Add developer option feature
Browse files Browse the repository at this point in the history
To test demo, and staging environment from the app side, developers can change the API key, base URL, org ID, and user ID.
  • Loading branch information
lijogeorgep authored and josmilan committed Nov 3, 2023
1 parent c1fe26a commit 803f2e7
Show file tree
Hide file tree
Showing 17 changed files with 812 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ class MainActivity : FlutterActivity() {
DataWallet.openShareData(this)
}
"Preferences" -> {
PrivacyDashboard.showPrivacyDashboard().withApiKey("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsic2VydmljZSJdLCJPcmdhbmlzYXRpb25JZCI6IjY0ZjA5Zjc3OGU1ZjM4MDAwMTRhODc5YSIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2NTBhZTFmYmJlMWViNDAwMDE3MTFkODciLCJleHAiOjE3MzAyMjMyODh9.DlU8DjykYr3eBmbgsKLR4dnaChiRqXdxofKOuk4LiRM")
.withUserId("653fe90efec9f34efed23619")
.withOrgId("64f09f778e5f3800014a879a")
.withBaseUrl("https://demo-consent-bb-api.igrant.io/")
val apiKey: String? = call.argument("ApiKey")
val orgId: String? = call.argument("orgId")
val baseUrl: String?= call.argument("baseUrl")
val userId: String?= call.argument("userId")
println("lijo $apiKey,$orgId,$baseUrl,$userId")
PrivacyDashboard.showPrivacyDashboard().withApiKey(apiKey ?: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsic2VydmljZSJdLCJPcmdhbmlzYXRpb25JZCI6IjY0ZjA5Zjc3OGU1ZjM4MDAwMTRhODc5YSIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2NTBhZTFmYmJlMWViNDAwMDE3MTFkODciLCJleHAiOjE3MzAyMjMyODh9.DlU8DjykYr3eBmbgsKLR4dnaChiRqXdxofKOuk4LiRM")
.withUserId(userId ?: "653fe90efec9f34efed23619")
.withOrgId(orgId ?: "64f09f778e5f3800014a879a")
.withBaseUrl(baseUrl ?: "https://demo-consent-bb-api.igrant.io/")
// .enableUserRequest()
// .enableAskMe()
.start(this)
Expand Down
3 changes: 2 additions & 1 deletion lib/app/core/base/base_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ abstract class BaseView<Controller extends BaseController>
}

Color statusBarColor() {
return AppColors.pageBackground;
//return AppColors.pageBackground;
return Colors.transparent;
}

Widget? floatingActionButton() {
Expand Down
14 changes: 14 additions & 0 deletions lib/app/modules/developerOptions/bindings/credentials_binding.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import 'package:get/get.dart';
import 'package:get/get_instance/src/bindings_interface.dart';

import '../controllers/credentials_controller.dart';

class CredentialsBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<CredentialsController>(
() => CredentialsController(),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import 'package:get/get.dart';
import 'package:get/get_instance/src/bindings_interface.dart';

import '../controllers/dexcom_credential_controller.dart';

class DexcomCredentialsBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<DexcomCredentailController>(
() => DexcomCredentailController(),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import 'package:get/get.dart';
import 'package:get/get_instance/src/bindings_interface.dart';

import '../controllers/privacy_dashboard_credential_controller.dart';

class PrivacyDashboardCredentialsBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<PrivacyDashboardCredentialController>(
() => PrivacyDashboardCredentialController(),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:Data4Diabetes/app/core/base/base_controller.dart';

import 'package:get/get.dart';

import '../views/dexcom_credential_view.dart';
import '../views/privacy_dashboard_credential_view.dart';

class CredentialsController extends BaseController{
setPrivacyDashboardCred(){
Get.to(PrivacyDashboardCredentialView());
}
setDexcomCred(){
Get.to(DexcomCredentialView());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:Data4Diabetes/app/core/base/base_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../../../../flavors/build_config.dart';
import '../../Dexcom/controllers/dexcom_controller.dart';

class DexcomCredentailController extends BaseController{
final DexcomController _dexcomController = Get.find();
var firstRadioButtonSelected = true.obs;
final TextEditingController baseUrlController = TextEditingController();
@override
void onInit() async {
super.onInit();
// Retrieve the stored value from SharedPreferences
final prefs = await SharedPreferences.getInstance();
final storedValue = prefs.getBool('firstRadioButtonSelected');

if (storedValue != null) {
// Use the stored value if it exists
firstRadioButtonSelected.value = storedValue;
} else {
// If no value is stored, set the default value
firstRadioButtonSelected.value = true;

// You may also want to store the default value
prefs.setBool('firstRadioButtonSelected', true);
}
}
// Update the selected value and store it in SharedPreferences
void updateSelectedValue(bool value) async {
firstRadioButtonSelected.value = value;
final prefs = await SharedPreferences.getInstance();
prefs.setBool('firstRadioButtonSelected', value);
}
Future<void> defaultDexcomEnvironment() async {
final prefs = await SharedPreferences.getInstance();
prefs.setString('dexcomStoredBaseUrl', BuildConfig.instance.config.dexComBaseUrl!);
_dexcomController.dexComBaseUrl.value =
BuildConfig.instance.config.dexComBaseUrl!;
Get.rawSnackbar(message: 'Changed url successfully',backgroundColor: Colors.green);
}

Future<void> limitedDexcomEnvironment() async {
final prefs = await SharedPreferences.getInstance();
prefs.setString('dexcomStoredBaseUrl', 'https://api.dexcom.com');
_dexcomController.dexComBaseUrl.value = 'https://api.dexcom.com';

print('changed url${_dexcomController.dexComBaseUrl.value}');
Get.rawSnackbar(message: 'Changed url successfully',backgroundColor: Colors.green);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:Data4Diabetes/app/core/base/base_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

class PrivacyDashboardCredentialController extends BaseController {
var platform = const MethodChannel('io.igrant.data4diabetes.channel');

final TextEditingController apiKeyController = TextEditingController();
final TextEditingController baseUrlController = TextEditingController();
final TextEditingController orgIdController = TextEditingController();
final TextEditingController userIdController = TextEditingController();
@override
void onInit() {
super.onInit();
privacyDashboardCredentials();
}

privacyDashboardCredentials() async {
SharedPreferences _prefs = await SharedPreferences.getInstance();
var apiKey = _prefs.getString('privacyDashboardApiKey');
var orgId = _prefs.getString('privacyDashboardorgId');
var baseUrl = _prefs.getString('privacyDashboardbaseUrl');
var userId = _prefs.getString('privacyDashboarduserId');
print('apikey now:$apiKey');
apiKey != null
? apiKeyController.text = apiKey
: apiKeyController.text =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsic2VydmljZSJdLCJPcmdhbmlzYXRpb25JZCI6IjY0ZjA5Zjc3OGU1ZjM4MDAwMTRhODc5YSIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2NTBhZTFmYmJlMWViNDAwMDE3MTFkODciLCJleHAiOjE3MzAyMjMyODh9.DlU8DjykYr3eBmbgsKLR4dnaChiRqXdxofKOuk4LiRM";
orgId != null
? orgIdController.text = orgId
: orgIdController.text = "64f09f778e5f3800014a879a";
baseUrl != null
? baseUrlController.text = baseUrl
: baseUrlController.text = "https://demo-consent-bb-api.igrant.io/";
userId != null
? userIdController.text = userId
: userIdController.text = "653fe90efec9f34efed23619";
print('apiKeyController.text${apiKeyController.text}');
}

submitButtonAction() async {
SharedPreferences _prefs = await SharedPreferences.getInstance();
_prefs.setString('privacyDashboardApiKey', apiKeyController.text);
_prefs.setString('privacyDashboardorgId', orgIdController.text);
_prefs.setString('privacyDashboardbaseUrl', baseUrlController.text);
_prefs.setString('privacyDashboarduserId', userIdController.text);
Get.rawSnackbar(
message: 'updated credentials successfully',
backgroundColor: Colors.green);
privacyDashboardCredentials();
}
resetButtonAction() async {
SharedPreferences _prefs = await SharedPreferences.getInstance();
_prefs.setString('privacyDashboardApiKey', "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsic2VydmljZSJdLCJPcmdhbmlzYXRpb25JZCI6IjY0ZjA5Zjc3OGU1ZjM4MDAwMTRhODc5YSIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2NTBhZTFmYmJlMWViNDAwMDE3MTFkODciLCJleHAiOjE3MzAyMjMyODh9.DlU8DjykYr3eBmbgsKLR4dnaChiRqXdxofKOuk4LiRM");
_prefs.setString('privacyDashboardorgId', "64f09f778e5f3800014a879a");
_prefs.setString('privacyDashboardbaseUrl', "https://demo-consent-bb-api.igrant.io/");
_prefs.setString('privacyDashboarduserId', "653fe90efec9f34efed23619");
privacyDashboardCredentials();
Get.rawSnackbar(
message: 'Reset to default credentials',
backgroundColor: Colors.green);
privacyDashboardCredentials();
}
}
115 changes: 115 additions & 0 deletions lib/app/modules/developerOptions/views/credentials_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/preferred_size.dart';
import 'package:get/get.dart';

import '../../../Constants/Palette.dart';
import '../../../core/base/base_view.dart';
import '../../../core/values/app_colors.dart';
import '../../../core/widget/app_bar_title.dart';
import '../controllers/credentials_controller.dart';

class CredentailsView extends BaseView<CredentialsController> {
final CredentialsController _credentialsController = Get.find();
static const double containerRaduis = 20;
@override
PreferredSizeWidget? appBar(BuildContext context) {
return AppBar(
backgroundColor: Palette.backgroundColor,
//centerTitle: true,
elevation: 0,
automaticallyImplyLeading: true,
leading: IconButton(
onPressed: () {
Get.back();
},
icon: const Icon(Icons.arrow_back_ios),
),
iconTheme: const IconThemeData(color: AppColors.appBarIconColor),
title: const AppBarTitle(text: 'Developer Options'),
);
}

@override
Widget body(BuildContext context) {
return Scaffold(
backgroundColor: Palette.backgroundColor,
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
child: Container(
decoration: BoxDecoration(
color: Palette.white,
border: Border.all(color: Palette.white),
borderRadius: const BorderRadius.all(
Radius.circular(containerRaduis))),
child: Column(
children: [
_privacyDashboardCredWidget(),
const Divider(),
_dexcomCredWidget(),
],
),
),
),
],
),
),
);
}

_privacyDashboardCredWidget() {
return ListTile(
dense: true,
visualDensity: const VisualDensity(horizontal: 0, vertical: -3),
title: const Text(
'Privacy Dashboard',
style: TextStyle(
fontSize: 14,
),
),
trailing: const Icon(
Icons.arrow_forward_ios,
size: 15.0,
),
onTap: () {
// if (Platform.isAndroid) {

_credentialsController.setPrivacyDashboardCred();
// } else if (Platform.isIOS) {
// showToast('Coming soon');
// }
},
);

}

_dexcomCredWidget() {
return ListTile(
dense: true,
visualDensity: const VisualDensity(horizontal: 0, vertical: -3),
title: const Text(
'Dexcom',
style: TextStyle(
fontSize: 14,
),
),
trailing: const Icon(
Icons.arrow_forward_ios,
size: 15.0,
),
onTap: () {
// if (Platform.isAndroid) {
_credentialsController.setDexcomCred();
// } else if (Platform.isIOS) {
// showToast('Coming soon');
// }
},
);

}
}
Loading

0 comments on commit 803f2e7

Please sign in to comment.