tencent_ad 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 59

tencent_ad #

Flutter腾讯广告插件, 目前只支持Android,IOS端正在封装

1.0.0 #

  • 更新内容 ● 集成Android端腾讯广告,包含横幅、插屏、渲染模版、闪屏等广告页面。 ● Android端使用的Jar包为X5增强版,4.11 https://adnet.qq.com/resource/sdk ● Android端的插屏弹窗广告目前显示异常,待解决。 ● Android端运行Demo项目,自动生成的绑定插件类是Java文件,而源码是Kotlin, 调用静态方法需要手动修改为 Companion 。 ● IOS端仅能运行静态页面,尚未调用到库。

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:tencent_ad/tencent_ad.dart';

final config = defaultTargetPlatform == TargetPlatform.iOS
    ? {
        'appID': '1105344611',
        'bannerID': '1080958885885321',
        'nativeID': '1020922903364636',
        'intersID': '1050652855580392',
        'splashID': '9040714184494018',
        'bgPic': 'LaunchImage'
      }
    : {
        'appID': '1101152570',
        'bannerID': '4080052898050840',
        'nativeID': '2000629911207832',
        'intersID': '3040652898151811',
        'splashID': '8863364436303842593',
        'bgPic': 'tencent.ad_example:mipmap/splash_img'
      };

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  try {
    TencentAD.config(appID: config['appID'], phoneSTAT: 0, fineLOC: 0).then(
        (_) => SplashAd(config['splashID'], bgPic: config['bgPic']).showAd());
  } on PlatformException {}
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _adClosed = false;
  GlobalKey<UnifiedBannerAdState> _adKey = GlobalKey();
  IntersAD _intersAD;

  void _adEventCallback(BannerEvent event, dynamic arguments) {
    if (event == BannerEvent.onAdClosed) {
      if (this.mounted) {
        this.setState(() {
          _adClosed = true;
        });
      }
    }
  }

  Future<void> _intersADCallback(IntersEvent event, dynamic args) async {
    if (event == IntersEvent.onADReceive) {
      _intersAD.loadAD();
    }
  }

  @override
  void initState() {
    _intersAD = IntersAD(config['intersID'], callback: _intersADCallback);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(),
        body: ListView(
          children: <Widget>[
            Column(
              children: <Widget>[
                Container(
                  height: _adClosed ? 0 : UnifiedBannerAd.ratio,
                  child: _adClosed
                      ? Container()
                      : UnifiedBannerAd(config['bannerID'],
                          key: _adKey,
                          adEventCallback: _adEventCallback,
                          refreshOnCreate: true),
                ),
                Row(
                  children: <Widget>[
                    RaisedButton(
                      onPressed: () {
                        this.setState(() => this._adClosed = false);
                        _adKey.currentState?.loadAD();
                      },
                      child: Text('刷新横幅'),
                    ),
                    RaisedButton(
                      onPressed: () async {
                        await _adKey.currentState?.closeAD();
                        if (this.mounted) {
                          this.setState(() => _adClosed = true);
                        }
                      },
                      child: Text('关闭横幅'),
                    ),
                  ],
                ),
              ],
            ),
            SizedBox(
              height: 500.0,
              child: NativeExpress(),
            ),
            Row(
              children: <Widget>[
                RaisedButton(
                  child: Text('加载插屏'),
                  onPressed: () {
                    _intersAD.loadAD();
                  },
                ),
                RaisedButton(
                  child: Text('关闭插屏'),
                  onPressed: () {
                    _intersAD.closeAD();
                  },
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}

class NativeExpress extends StatefulWidget {
  @override
  _NativeExpressState createState() => _NativeExpressState();
}

class _NativeExpressState extends State<NativeExpress> {
  double adHeight;

  bool adRemoved = false;

  GlobalKey<NativeExpressAdState> _adKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(
        children: <Widget>[
          Row(
            children: <Widget>[
              RaisedButton(
                onPressed: () {
                  setState(() {
                    adHeight = null;
                    adRemoved = false;
                  });
                  _adKey.currentState?.refreshAd();
                },
                child: Text('刷新消息流'),
              ),
              RaisedButton(
                onPressed: () async {
                  await _adKey.currentState?.closeAd();
                  if (this.mounted) {
                    this.setState(() {
                      adRemoved = true;
                      adHeight = null;
                    });
                  }
                },
                child: Text('关闭消息流'),
              ),
            ],
          ),
          adRemoved
              ? Container()
              : Container(
                  height: adHeight == null ? 1 : adHeight,
                  child: NativeExpressAd(
                    key: _adKey,
                    posId: config['nativeID'],
                    callback: _adEventCallback,
                    refreshOnCreate: true,
                  ),
                ),
          Container(
            height: 200.0,
            color: Colors.accents[0],
          ),
          NativeExpressAdWidget(config['nativeID']),
        ],
      ),
    );
  }

  void _adEventCallback(NativeADEvent event, dynamic arguments) async {
    if (event == NativeADEvent.onLayoutChange && this.mounted) {
      this.setState(() {
        // 根据选择的广告位模板尺寸计算,这里是1280x720
        adHeight = MediaQuery.of(context).size.width *
            arguments['height'] /
            arguments['width'];
      });
      return;
    }
    if (event == NativeADEvent.onADClosed) {
      this.setState(() {
        adRemoved = true;
      });
    }
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  tencent_ad: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:tencent_ad/tencent_ad.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
34
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/inters.dart.

Run flutter format to format lib/inters.dart.

Format lib/native.dart.

Run flutter format to format lib/native.dart.

Maintenance issues and suggestions

The description contains too many non-ASCII characters. (-20 points)

The site uses English as its primary language. The value of the description field in your package's pubspec.yaml field should primarily contain characters used in English.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test