import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
static const platform = MethodChannel('com.example.offerwall_app');
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('AdJump Example')),
body: Center(
child: ElevatedButton(
onPressed: () {
_launchOfferWall();
},
child: Text('Launch OfferWall'),
),
),
),
);
}
Future<void> _launchOfferWall() async {
try {
final Map<String, String> params = {
'accountId': 'YOUR_ACCOUNT_ID',
'appId': 'YOUR_APP_ID',
'userId': 'USER_ID',
};
await platform.invokeMethod('launchOfferWall', params);
} on PlatformException catch (e) {
print("Failed to show offer wall: '${e.message}'.");
}
}
}
package com.example.adjump
import android.widget.Toast
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.adjump.offerwall.AdJump
class MainActivity : FlutterActivity() {
private val CHANNEL = "com.example.offerwall_app"
private var adJump: AdJump? = null
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
.setMethodCallHandler { call, result ->
when (call.method) {
"launchOfferWall" -> {
val arguments = call.arguments as? Map<*, *>
if (arguments != null) {
val accountId = arguments["accountId"] as? String
val appId = arguments["appId"] as? String
val userId = arguments["userId"] as? String
if (accountId != null && appId != null && userId != null) {
adJump = AdJump(this, accountId, appId, userId)
launchOfferWall()
result.success("Offer wall launched")
} else {
result.error("INVALID_ARGUMENTS", "Missing required parameters", null)
}
} else {
result.error("INVALID_ARGUMENTS", "Arguments are required", null)
}
}
else -> result.notImplemented()
}
}
}
private fun launchOfferWall() {
adJump?.initialize(object : AdJump.InitialisationListener {
override fun onInitialisationSuccess() {
runOnUiThread { Toast.makeText(this@MainActivity, "AdJump SDK Initialized", Toast.LENGTH_SHORT).show() }
if (adJump?.isAvailable == true) {
adJump?.launchOfferWall()
} else {
Toast.makeText(this@MainActivity, "Offerwall not available!", Toast.LENGTH_SHORT).show()
}
}
override fun onInitialisationError(exception: Exception) {
runOnUiThread { Toast.makeText(this@MainActivity, "Initialization failed: ${exception.message}", Toast.LENGTH_SHORT).show() }
}
})
}
}