cs_tapjoy_ad 0.0.3 copy "cs_tapjoy_ad: ^0.0.3" to clipboard
cs_tapjoy_ad: ^0.0.3 copied to clipboard

Tapjoy 广告SDK

example/lib/main.dart

import 'package:cs_tapjoy_ad/cs_tapjoy_ad_listener.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:cs_tapjoy_ad/cs_tapjoy_ad.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with CsTapjoyAdListener {
  String _platformVersion = 'Unknown';
  final String _placementName = 'Tapjoy Offerwall Location';
  final _csTapjoyAdPlugin = CsTapjoyAd();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion = "准备初始化!!!!";
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      await _csTapjoyAdPlugin.setTapjoyAdListener(this);
      await _csTapjoyAdPlugin.initialize("xxxxxxxxxxx") ?? 'Unknown platform version';
      await _csTapjoyAdPlugin.setDebug(true);
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  /// 初始化成功
  @override
  void onInitSuccess() {
    debugPrint("cs_tapjoy_ad onInitSuccess");
    setState(() {
      _platformVersion = "SDK 初始化成功";
    });
  }

  /// 初始化失败
  @override
  void onInitFailed() {
    debugPrint("cs_tapjoy_ad onInitFailed");
  }

  /// 初始化成功
  @override
  void onSetUserIdSuccess() {
    debugPrint("cs_tapjoy_ad onSetUserIdSuccess");
  }

  /// 初始化失败
  @override
  void onSetUserIdFailed(String errMsg) {
    debugPrint("cs_tapjoy_ad onSetUserIdFailed - msg:$errMsg");
  }

  @override
  void onRequestSuccess(String? placementName) {
    debugPrint("cs_tapjoy_ad onRequestSuccess - pn:$placementName");
    setState(() {
      _platformVersion = "请求 placement 成功";
    });
  }

  @override
  void onRequestFailure(String? placementName, int? errCode, String? errMsg) {
    debugPrint("cs_tapjoy_ad onRequestFailure - pn:$placementName");
  }

  @override
  void onContentReady(String? placementName) {
    debugPrint("cs_tapjoy_ad onContentReady - pn:$placementName");
  }

  @override
  void onContentShow(String? placementName) {
    debugPrint("cs_tapjoy_ad onContentShow - pn:$placementName");
  }

  @override
  void onContentDismiss(String? placementName) {
    debugPrint("cs_tapjoy_ad onContentDismiss - pn:$placementName");
  }

  @override
  void onPurchaseRequest(String? placementName, String? requestToken, String? productId) {
    debugPrint("cs_tapjoy_ad onPurchaseRequest - pn:$placementName");
  }

  @override
  void onRewardRequest(String? placementName, String? itemId, int quantity) {
    debugPrint("cs_tapjoy_ad onRewardRequest - pn:$placementName");
  }

  @override
  void onClick(String? placementName) {
    debugPrint("cs_tapjoy_ad onClick - pn:$placementName");
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                _platformVersion,
                style: const TextStyle(fontSize: 20, color: Colors.black),
              ),
              const SizedBox(height: 100),
              ElevatedButton(
                onPressed: () {
                  _csTapjoyAdPlugin.requestPlacement(_placementName);
                },
                child: const Text(
                  "请求广告",
                  style: TextStyle(fontSize: 20, color: Colors.black),
                ),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: () {
                  _csTapjoyAdPlugin.showPlacement(_placementName);
                },
                child: const Text(
                  "展示广告",
                  style: TextStyle(fontSize: 20, color: Colors.black),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
125
points
14
downloads

Publisher

unverified uploader

Weekly Downloads

Tapjoy 广告SDK

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on cs_tapjoy_ad

Packages that implement cs_tapjoy_ad