vcip_sdk_new 0.0.5
vcip_sdk_new: ^0.0.5 copied to clipboard
A Flutter package for handling VCIP (Video Customer Identification Process) with features for PAN card input and result display.
example/lib/main.dart
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:android_intent_plus/android_intent.dart';
import 'package:app_links/app_links.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_instance/src/extension_instance.dart';
import 'package:get/get_navigation/src/extension_navigation.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:get/get_navigation/src/snackbar/snackbar.dart';
import 'package:get/get_rx/src/rx_workers/rx_workers.dart';
import 'package:vcip_sdk_new/models/FaceAuthCallBackResponse.dart';
import 'package:vcip_sdk_new/my_full_sdk.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'DeepLinkService.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isAndroid) {
await InAppWebViewController.setWebContentsDebuggingEnabled(true);
}
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Flutter Demo',
home: const SDKExamplePage(),
);
}
}
class SDKExamplePage extends StatefulWidget {
const SDKExamplePage({super.key});
@override
State<SDKExamplePage> createState() => _SDKExamplePageState();
}
class _SDKExamplePageState extends State<SDKExamplePage> {
String finalresult = "Press the button";
String _pendingTxnId = "";
bool _callbackHandled = false;
Worker? _uriWorker;
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("SDK Button Example")),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SelectableText(finalresult, style: const TextStyle(fontSize: 12)),
// Text(finalresult, style: const TextStyle(fontSize: 12),),
const SizedBox(height: 20),
ElevatedButton(
onPressed: onButtonClick,
child: const Text("Call SDK"),
),
ElevatedButton(
onPressed: () async {
final result = await MySdk.startFaceAuthFlow(
context,
mobileNumber: "9999999999",
companyCode: "TA001",
entityID: 77,
);
_showSdkResponsePopup(context, result);
},
child: const Text("Face Authentication"),
),
],
),
),
),
);
}
Future<void> onButtonClick() async {
final result = await MySdk.startKycFlow(
context,
mobileNumber: '7777777777',
entityID: 77,
IsFaceAuthNeed: false,
autoSubmitIfPrefilled: true,
companyCode: "TA001",
// TA001 //ISU001 //SPY001 for entity id 87
applicationId: "com.example.example",
appSignature:
"90:E7:69:55:63:28:5F:18:9D:1A:70:D5:61:44:71:C6:36:3B:4F:DA:50:59:E5:BE:26:2A:46:2E:6F:07:97:6F",
);
if (result.intenturl != null) {
_pendingTxnId = result.txnId ?? "";
// await _openAadhaarIntent(result.intenturl!);
final result1 = await NativeBridge.openAadhaarApp(result.intenturl ?? "");
if (result1.containsKey("error")) {
if (result1["error"] == "Please install Aadhaar app") {
_showInstallDialog();
} else {
Get.snackbar(
"Cancelled",
result1["error"],
snackPosition: SnackPosition.BOTTOM,
);
}
return;
}
print(result1["response"]);
setState(() {
finalresult = result1["response"];
});
Get.defaultDialog(
title: "Native Response",
content: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Status : ${result1["status"]}"),
const SizedBox(height: 10),
Text("Timestamp : ${result1["timestamp"]}"),
const SizedBox(height: 10),
/* const Text(
"Response :",
style: TextStyle(fontWeight: FontWeight.bold),
),*/
/*SelectableText(
result1["response"] ?? "",
style: const TextStyle(fontSize: 12),
),*/
],
),
),
textConfirm: "OK",
onConfirm: () async {
var result2 = await MySdk.submitToBackend(
result1["status"],
result.txnId ?? "",
result1["response"],
result1["timestamp"],
);
if (result2 != null) {
setState(() {
finalresult = result2.intenturl ?? "";
Get.snackbar(result2.responsecode, result2.message);
});
Get.back();
}
},
);
} else {
print("SDK Response>>>>" + result.toString());
}
}
Future<void> _openAadhaarIntent(String intentUrl) async {
_callbackHandled = false;
if (Platform.isAndroid) {
await _launchAndroid(intentUrl);
} else {
await _launchIOS(intentUrl);
}
}
Future<void> _launchAndroid(String intentUrl) async {
try {
final withoutScheme = intentUrl
.replaceFirst('intent:#Intent;', '')
.replaceFirst(';end', '');
String? action;
final Map<String, String> extras = {};
for (final part in withoutScheme.split(';')) {
if (part.startsWith('action=')) {
action = part.replaceFirst('action=', '');
} else if (part.startsWith('S.')) {
final kv = part.replaceFirst('S.', '').split('=');
if (kv.length >= 2) {
extras[kv[0]] = kv.sublist(1).join('='); // handles '=' inside JWT
}
}
}
print("Action: $action");
print("Extras: $extras");
final intent = AndroidIntent(
action: action ?? 'in.gov.uidai.pehchaan.INTENT_REQUEST',
arguments: extras,
flags: <int>[0x10000000], // FLAG_ACTIVITY_NEW_TASK
);
final canResolve = await intent.canResolveActivity();
print("Can resolve mAadhaar: $canResolve");
if (canResolve!) {
await intent.launch();
} else {
// Android 11+ package visibility can cause false negative
// Try launching anyway before giving up
try {
await intent.launch();
print("Launched despite canResolve=false");
} catch (e) {
print("Launch failed: $e");
_showInstallDialog();
}
}
} on PlatformException catch (e) {
print("PlatformException: ${e.message}");
if (e.message?.contains('No Activity') == true) {
_showInstallDialog();
} else {
Get.snackbar(
"Error",
"Failed to open Aadhaar app: ${e.message}",
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red,
);
}
}
}
Future<void> _launchIOS(String intentUrl) async {
try {
final uri = Uri.parse(intentUrl);
if (!await launchUrl(uri, mode: LaunchMode.externalApplication)) {
_showInstallDialog();
}
} catch (e) {
_showInstallDialog();
}
}
void _showInstallDialog() {
Get.dialog(
AlertDialog(
title: const Text("App Required"),
content: const Text(
"mAadhaar app is required to complete verification. "
"Please install it from the Play Store.",
),
actions: [
TextButton(onPressed: () => Get.back(), child: const Text("Cancel")),
TextButton(
onPressed: () {
Get.back();
_openPlayStore();
},
child: const Text("Install"),
),
],
),
);
}
Future<void> _openPlayStore() async {
const packageName = "in.gov.uidai.pehchaan";
try {
await launchUrl(
Uri.parse("market://details?id=$packageName"),
mode: LaunchMode.externalApplication,
);
} catch (_) {
await launchUrl(
Uri.parse("https://play.google.com/store/apps/details?id=$packageName"),
mode: LaunchMode.externalApplication,
);
}
}
void _showSdkResponsePopup(
BuildContext context,
FaceAuthCallbackresponse result,
) {
final Map<String, dynamic> responseJson = {
"success": result.success,
"message": result.message,
"data": result.data,
};
final String formattedResponse =
const JsonEncoder.withIndent(' ').convert(responseJson);
showDialog(
context: context,
barrierDismissible: false,
builder: (dialogContext) {
return AlertDialog(
title: Text(
result.success ? "Success" : "Failed",
),
content: SizedBox(
width: double.maxFinite,
height: 450,
child: SingleChildScrollView(
child: SelectableText(
formattedResponse,
style: const TextStyle(
fontSize: 13,
fontFamily: 'monospace',
),
),
),
),
actions: [
TextButton(
onPressed: () {
Navigator.of(dialogContext).pop();
},
child: const Text("OK"),
),
],
);
},
);
}
}