flutter_tapjoy 1.0.1 flutter_tapjoy: ^1.0.1 copied to clipboard
A plugin for Tapjoy SDK Ads & Offerwall for both Android & iOS
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_tapjoy/tapjoy.dart';
import 'package:flutter_tapjoy/tj_placement.dart';
import 'package:flutter_tapjoy/listeners.dart';
import 'dart:io';
void main() async {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Future<void> initTapjoy() async {
if (Platform.isAndroid) {
Tapjoy.setDebugEnabled(true);
Tapjoy.setUserConsent('1');
Tapjoy.connect(
'api_key',
tapjoyConnectSuccess,
tapjoyConnectFailure,
);
} else if (Platform.isIOS) {
TapjoyiOS.setDebugEnabled(true);
TapjoyiOS.setUserConsent('1');
TapjoyiOS.connect(
'api_key');
}
}
void tapjoyConnectSuccess() {
Tapjoy.setActivity();
print('Tapjoy SDK connected');
}
void tapjoyConnectFailure() {
print('Tapjoy SDK connection failure');
}
listener(TapjoySwiftListener event) {
switch (event) {
case TapjoySwiftListener.contentIsReady:
print('TAPJOY: content is ready');
TapjoyiOS.showContent();
break;
case TapjoySwiftListener.requestDidFail:
print('TAPJOY: request failed');
break;
case TapjoySwiftListener.requestDidSucceed:
print('TAPJOY: request successful');
break;
case TapjoySwiftListener.didRequestReward:
print('TAPJOY: reward requested');
break;
case TapjoySwiftListener.contentDidAppear:
print('TAPJOY: content did appear');
break;
case TapjoySwiftListener.contentDidDisappear:
print('TAPJOY: content did disappear');
break;
}
}
@override
void initState() {
initTapjoy();
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: <Widget>[
RaisedButton(
child: Text('is Content Available'),
onPressed: () async {
if (Platform.isAndroid) {
TJPlacement tjPlacement = await Tapjoy.getPlacement('placement_name',
onRequestSuccess: (placement) => placement.showContent(),
onRequestFailure: (placement, error) => print(
error.errorCode.toString() +
' - ' +
error.errorMessage));
tjPlacement.requestContent();
} else if (Platform.isIOS) {
TapjoyiOS.getPlacement('placement_name');
TapjoyiOS.requestContent(listener);
}
},
),
],
),
),
);
}
}