// CashoutGuard for Flutter (Android), through a platform channel to the native Android SDK. // // 1. android/settings.gradle (or the root build.gradle), repositories: // maven { url 'https://cashoutguard.com/maven' } // android/app/build.gradle, dependencies: // implementation 'com.cashoutguard:cashoutguard-android:1.1.0' // // 2. android/app/src/main/kotlin/.../MainActivity.kt: // // import com.cashoutguard.android.CashoutGuard // import io.flutter.embedding.android.FlutterActivity // import io.flutter.embedding.engine.FlutterEngine // import io.flutter.plugin.common.MethodChannel // // class MainActivity : FlutterActivity() { // override fun configureFlutterEngine(flutterEngine: FlutterEngine) { // super.configureFlutterEngine(flutterEngine) // MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "cashoutguard").setMethodCallHandler { call, result -> // when (call.method) { // "init" -> { CashoutGuard.init(applicationContext, call.argument("key") ?: ""); result.success(null) } // "collect" -> CashoutGuard.collect(call.argument("event") ?: "custom") { requestId -> result.success(requestId) } // else -> result.notImplemented() // } // } // } // } // // 3. This file in lib/, then: // await CashoutGuard.init('pk_live_YOUR_PUBLIC_KEY'); // once, at startup (public key only) // final requestId = await CashoutGuard.collect('cashout'); // before signup, offer clicks, cashout // Send requestId to your server with the request; your server asks POST https://cashoutguard.com/v1/evaluate. // // Never throws: on iOS (no native SDK yet), on any error, or after 2 seconds, collect() returns null and your server // evaluates without device data. import 'dart:async'; import 'dart:io' show Platform; import 'package:flutter/services.dart'; class CashoutGuard { static const MethodChannel _channel = MethodChannel('cashoutguard'); /// Starts the SDK with your site's public key (never the secret key). static Future init(String publicKey) async { if (!Platform.isAndroid) return; try { await _channel.invokeMethod('init', {'key': publicKey}); } catch (_) { // Fail open: the app keeps working without device signals. } } /// Scans the device for [event] ('signup', 'login', 'offer_click', 'cashout'...) and returns the request id to send /// to your server, or null. static Future collect(String event) async { if (!Platform.isAndroid) return null; try { return await _channel .invokeMethod('collect', {'event': event}) .timeout(const Duration(seconds: 3), onTimeout: () => null); } catch (_) { return null; } } }