v1.0.6
Flutter Bridge
Full templates for the Kotlin MainActivity bridge and Dart wrapper class. v1.0.6 uses Gson for serializing AbleCreditLoanResponse.
Dart bridge
// lib/ablecredit_sdk_bridge.dart
import 'package:flutter/services.dart';
class AbleCreditSdkBridge {
static const MethodChannel _channel = MethodChannel('ablecredit/wrapper_sdk');
static const EventChannel _audioUploadStatusChannel = EventChannel('ablecredit/audio_upload_status');
static Future<Map<String, dynamic>> configure({
required String apiKey,
required String tenantId,
required String userId,
required String baseUrl,
}) async {
final dynamic res = await _channel.invokeMethod('configure', {
'apiKey': apiKey, 'tenantId': tenantId, 'userId': userId, 'baseUrl': baseUrl,
});
return Map<String, dynamic>.from(res as Map);
}
static Future<Map<String, dynamic>> createNewLoanCase(Map<String, dynamic> payload) async {
final dynamic res = await _channel.invokeMethod('createNewLoanCase', {'payload': payload});
return Map<String, dynamic>.from(res as Map);
}
static Future<void> recordAudio(String id) => _channel.invokeMethod('recordAudio', {'loanApplicationId': id});
static Future<void> captureFamilyPhotos(String id) => _channel.invokeMethod('captureFamilyPhotos', {'loanApplicationId': id});
static Future<void> captureBusinessPhotos(String id) => _channel.invokeMethod('captureBusinessPhotos', {'loanApplicationId': id});
static Future<void> captureCollateralPhotos(String id) => _channel.invokeMethod('captureCollateralPhotos', {'loanApplicationId': id});
static Future<void> clearSdkData() => _channel.invokeMethod('clearSdkData');
static Stream<Map<String, dynamic>> get audioUploadStatusStream {
return _audioUploadStatusChannel.receiveBroadcastStream().map(
(event) => Map<String, dynamic>.from(event as Map),
);
}
}MainActivity.kt (with Gson serialization)
// android/app/src/main/kotlin/<your_package>/MainActivity.kt
package com.example.app
import com.google.gson.Gson
import com.ablecredit.sdk.manager.AbleCredit
import com.ablecredit.sdk.model.AbleCreditFileStatus
import com.ablecredit.sdk.model.AbleCreditFileUploadListener
import com.ablecredit.sdk.model.AbleCreditLoanResponse
import com.ablecredit.sdk.model.AbleCreditResult
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodChannel
class MainActivity : FlutterActivity() {
private val gson = Gson()
private val channelName = "ablecredit/wrapper_sdk"
private val audioStatusChannelName = "ablecredit/audio_upload_status"
private var audioStatusSink: EventChannel.EventSink? = null
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
EventChannel(flutterEngine.dartExecutor.binaryMessenger, audioStatusChannelName)
.setStreamHandler(object : EventChannel.StreamHandler {
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) { audioStatusSink = events }
override fun onCancel(arguments: Any?) { audioStatusSink = null }
})
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channelName)
.setMethodCallHandler { call, result ->
when (call.method) {
"configure" -> {
val configResult = AbleCredit.configure(this,
call.argument<String>("apiKey").orEmpty(),
call.argument<String>("tenantId").orEmpty(),
call.argument<String>("userId").orEmpty(),
call.argument<String>("baseUrl").orEmpty()
)
when (configResult) {
is AbleCreditResult.Success -> result.success(mapOf("success" to true, "message" to "SDK configured"))
is AbleCreditResult.Failure -> result.success(mapOf("success" to false, "message" to configResult.message, "code" to configResult.ableCreditErrorCode.toString()))
}
}
"createNewLoanCase" -> {
val payload = call.argument<Map<String, Any?>>("payload") ?: emptyMap()
AbleCredit.createNewLoanCase(this, payload) { sdkResult -> result.success(serializeLoanResult(sdkResult)) }
}
"recordAudio" -> {
val id = call.argument<String>("loanApplicationId")
AbleCredit.recordAudio(context = this, loanApplicationId = id,
listener = object : AbleCreditFileUploadListener {
override fun onStatusChanged(uniqueId: String, status: AbleCreditFileStatus, message: String?) {
audioStatusSink?.success(mapOf("uniqueId" to uniqueId, "status" to status.name, "message" to message))
}
})
result.success(mapOf("success" to true))
}
"captureFamilyPhotos" -> { AbleCredit.captureFamilyPhotos(this, call.argument("loanApplicationId")); result.success(mapOf("success" to true)) }
"captureBusinessPhotos" -> { AbleCredit.captureBusinessPhotos(this, call.argument("loanApplicationId")); result.success(mapOf("success" to true)) }
"captureCollateralPhotos"-> { AbleCredit.captureCollateralPhotos(this, call.argument("loanApplicationId")); result.success(mapOf("success" to true)) }
"clearSdkData" -> { AbleCredit.clearSdkData { sdkResult -> result.success(mapOf("success" to (sdkResult is AbleCreditResult.Success))) } }
else -> result.notImplemented()
}
}
}
@Suppress("UNCHECKED_CAST")
private fun serializeLoanResult(sdkResult: AbleCreditResult<AbleCreditLoanResponse>): Map<String, Any?> {
return when (sdkResult) {
is AbleCreditResult.Success -> {
val loan = sdkResult.data
val dataMap: Map<String, Any?>? = loan?.let { gson.fromJson(gson.toJson(it), Map::class.java) as Map<String, Any?> }
val applicationId = try { loan?.data?.application?._id.orEmpty() } catch (_: Exception) { "" }
mapOf("success" to true, "message" to "OK", "applicationId" to applicationId, "data" to dataMap)
}
is AbleCreditResult.Failure -> mapOf("success" to false, "message" to sdkResult.message, "code" to sdkResult.ableCreditErrorCode.toString())
}
}
}Direct Calls (Mode 1 only)
v1.0.6 supports direct calls only. Use loanApplicationId as the identifier for all capture methods. No orchestrator or docked button in this version.
AbleCredit Android SDK – v1.0.4
v1.0.4 is a legacy release. It uses a local AAR file and follows the original API shape with initialize(), payload construction, and direct capture calls.