Skip to Content
Docs
Get startedPartner API v4Partner API v3Android SDK
v1.0.7

Flutter Bridge

Full templates for the native Kotlin MainActivity bridge and the Dart wrapper class for v1.0.7.

Dart bridge (lib/ablecredit_sdk_bridge.dart)

// 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,
    required String branchId,   // new in 1.0.7
  }) async {
    final dynamic res = await _channel.invokeMethod('configure', {
      'apiKey': apiKey, 'tenantId': tenantId, 'userId': userId,
      'baseUrl': baseUrl, 'branchId': branchId,
    });
    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<Map<String, dynamic>> fetchLoanDetails(String loanReference) async {
    final dynamic res = await _channel.invokeMethod('fetchLoanDetails', {'loanReference': loanReference});
    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 =>
      _audioUploadStatusChannel.receiveBroadcastStream().map(
        (event) => Map<String, dynamic>.from(event as Map),
      );
}

MainActivity.kt bridge

// android/app/src/main/kotlin/<your_package>/MainActivity.kt
package com.example.app

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 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(
              context  = this,
              apiKey   = call.argument<String>("apiKey").orEmpty(),
              tenantId = call.argument<String>("tenantId").orEmpty(),
              userId   = call.argument<String>("userId").orEmpty(),
              baseUrl  = call.argument<String>("baseUrl").orEmpty(),
              branchId = call.argument<String>("branchId").orEmpty(),
            )
            when (configResult) {
              is AbleCreditResult.Success -> result.success(mapOf("success" to true))
              is AbleCreditResult.Failure -> result.success(mapOf("success" to false, "message" to configResult.message))
            }
          }
          "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(this, id, 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()
        }
      }
  }

  private fun serializeLoanResult(sdkResult: AbleCreditResult<AbleCreditLoanResponse>): Map<String, Any?> {
    return when (sdkResult) {
      is AbleCreditResult.Success -> {
        val loan = sdkResult.data
        mapOf("success" to true, "applicationId" to (loan?.data?.application?._id ?: ""), "message" to "OK")
      }
      is AbleCreditResult.Failure -> mapOf("success" to false, "message" to sdkResult.message, "code" to sdkResult.ableCreditErrorCode.toString())
    }
  }
}

On this page