mintegralad 0.0.2 copy "mintegralad: ^0.0.2" to clipboard
mintegralad: ^0.0.2 copied to clipboard

Mintegral广告flutter版本

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:mintegralad/mintegralad.dart';
import 'package:mintegralad_example/banner_page.dart';
import 'package:mintegralad_example/native_page.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool _isRegister = false;
  String _sdkVersion = "";

  StreamSubscription? _adStream;

  @override
  void initState() {
    super.initState();
    _register();
    _adStream = MintegralAdStream.initAdStream(
      //激励广告
      rewardCallBack: MintegralAdRewardCallBack(
        onShow: () {
          print("激励广告显示");
        },
        onClick: () {
          print("激励广告点击");
        },
        onFail: (message) {
          print("激励广告失败 $message");
        },
        onClose: () {
          print("激励广告关闭");
        },
        onReady: () async {
          print("激励广告预加载准备就绪");
          await Mintegralad.showRewardAd();
        },
        onUnReady: () {
          print("激励广告预加载未准备就绪");
        },
        onVerify: (converted, rewardId,rewardName, rewardAmount) {
          print("激励广告奖励  是否完整播放=$converted  奖励id=$rewardId 奖励名称=$rewardName  奖励数量=$rewardAmount");
        },
      ),
    );
  }

  ///初始化
  Future<void> _register() async {
    _isRegister = await Mintegralad.register(
      //androidId
      androidId: "153806",
      //iosId
      iosId: "153806",
      //androidAppKey
      androidAppKey: "5ed0c480e4182fc44b2cc3064a2b6b32",
      //iosAppKey
      iosAppKey: "5ed0c480e4182fc44b2cc3064a2b6b32",
      //是否显示日志log
      debug: true,
      //是否显示个性化推荐广告
      personalized: true,
    );
    print("初始化==》$_isRegister");
    _sdkVersion = await Mintegralad.getSDKVersion();
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Mintegralad广告插件'),
      ),
      body: Center(
        child: Column(
          children: [
            Text('快手SDK初始化: $_isRegister\n'),
            Text('SDK版本: $_sdkVersion\n'),
            //激励广告
            MaterialButton(
              color: Colors.blue,
              textColor: Colors.white,
              child: const Text('激励广告'),
              onPressed: () async {
                await Mintegralad.loadRewardAd(
                  //android 广告版位ID
                  androidId: "351457",
                  //android 广告单元的ID
                  androidUnitId: "1589582",
                  //ios 广告版位ID
                  iosId: "351457",
                  //ios 广告单元的ID
                  iosUnitId: "1589582",
                  //奖励id
                  rewardId: "12",
                  //用户id
                  userId: "123",
                );
              },
            ),
            //横幅广告
            MaterialButton(
              color: Colors.blue,
              textColor: Colors.white,
              child: const Text('横幅广告'),
              onPressed: () async {
                Navigator.push(context, MaterialPageRoute(builder: (_) {
                  return const BannerPage();
                }));
              },
            ),
            //信息流广告
            MaterialButton(
              color: Colors.blue,
              textColor: Colors.white,
              child: const Text('信息流广告'),
              onPressed: () async {
                Navigator.push(context, MaterialPageRoute(builder: (_) {
                  return const NativePage();
                }));
              },
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
130
points
33
downloads

Publisher

unverified uploader

Weekly Downloads

Mintegral广告flutter版本

Homepage

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on mintegralad