flutter_ad_plugin 1.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 49

flutter_ad_plugin #

A new Flutter plugin.

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

1.0.0 #

  • TODO: Describe initial release.

example/README.md

环境 #

flutter 1.7

flutter_ad_plugin: ^1.1.0

gradle 5.1.1 以上 #

dependencies -> classpath 'com.android.tools.build:gradle:3.4.2'

gradle-wrapper.properties distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip

3.4 版本需要gradle 5.1 以上

android api 兼容 大于23 #

defaultConfig { applicationId "com.hua.flutter_app" minSdkVersion 23 targetSdkVersion 28 }

#1.android 目录下更改 build.gradle 文件

#新建支持 kotlin androidx

buildscript { ext.kotlin_version = '1.3.41' repositories { google() jcenter() }

 dependencies {
     classpath 'com.android.tools.build:gradle:3.4.2'
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
 }

}

allprojects { repositories { google() jcenter() maven { url "https://jitpack.io" } flatDir { dirs 'libs' } } }

#1.android main AndroidManifest.xml 更改
新增 xmlns:tools="http://schemas.android.com/tools" 新增 tools:replace="icon,label"

<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="flutter_app"
    tools:replace="icon,label"
    android:icon="@mipmap/ic_launcher">
    
    </application>
    

            

#2. MainActivity extends BaseActivity // FlutterActivity 替换 BaseActivity

    import android.os.Bundle
    import com.hua.flutter_ad_plugin.BaseActivity
    import io.flutter.plugins.GeneratedPluginRegistrant
    
    class MainActivity: BaseActivity() {
      override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        GeneratedPluginRegistrant.registerWith(this)
      }
    }

#Ad sdk 初始化调用 穿山甲初始化 VideoAd.initAdCsj({"code":"5001121","name":"APP测试媒体"}); 白青藤 VideoAd.initAdBaidu("e866cfb0");

监听 Android 端主动发送消息 #

static const EventChannel eventChannel = EventChannel('hua.ad.event');

eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);

接收消息 void _onEvent(Object event) { switch(event){ case 'onAdSkip': Navigator.pop(context); Navigator.pushNamed(context, '/screen2'); break; case 'next'://主动申请权限调用 , 用户确认后主动发发送,需要一个欢迎界面 Navigator.pop(context); Navigator.pushNamed(context, '/screen1'); break; } } 错误消息 void _onError(Object event) {

  }
  

onAdSkip //开瓶跳过调用 next 权限申请通过跳转 #视频回调 onSkippedVideo //跳过 onAdClick //点击 playCompletion //播放完毕 onAdClose //关闭

#激励视频初始化 穿山甲 百度 1。初始化 VideoAd.initVieo("901121365"); VideoAd.initVieoBaidu("5925490"); 2。调用 按钮调用视频 void showAd(){ //激励视频显示,需要初始化才能调用 // VideoAd.showVieo(); VideoAd.showVieoBaidu(); }

FrameView 广告显示 view #

Container( child: FrameView(onFrameViewCreated: _onFrameViewCreated,), height: 400, //width: 600, )

class FirstScreen1 extends StatelessWidget { @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text('feedAD'), ), body: Column(children:

   ],),
 );

}

void _onFrameViewCreated(FrameViewController controller) { //穿山甲 开屏广告 广告id controller.loadSplashAd('801121648'); //穿山甲 百度广告 广告id controller.loadSplashAdBaidu('2058622');

 //穿山甲  feed广告  广告id

controller.loadFeedAdCsj("901121737"); //百度 广告id controller.loadFeedAdBaidu("2058628");

//穿山甲   nativebanner 广告id

// controller.loadNativeAd("901121423"); //百度 nativebanner 广告id controller.loadBannerBaidu('2015351');

}

参考 example lib/main.dart

问题点 #

构建失败,单独打开android项目,build 成功,项目基本上没问题 如果构建失败,需要根据构建失败错误信息更改

#问题 1新建需要flutter项目需要支持kotlin 2。 支持Androidx

gradle.properties 文件

android.useAndroidX=true android.enableJetifier=true

权限修改 #

flutter_ad_plugin: ^1.0.4 //权限插件 permission_handler: '^3.2.0'

import 'package:permission_handler/permission_handler.dart';

requestPermiss() async { //请求权限 Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([PermissionGroup.phone,PermissionGroup.storage]); //校验权限

   if(permissions[PermissionGroup.storage] != PermissionStatus.granted||permissions[PermissionGroup.phone] != PermissionStatus.granted){
     print("手机状态");
     //bool isOpened = await PermissionHandler().openAppSettings();  打开设置
     // 弹窗提示

   }else{
     //下一个界面 next
     Navigator.pushNamed(context, '/screen1');
   }

 }
 
 
 

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_ad_plugin: ^1.1.1

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:flutter_ad_plugin/flutter_ad_plugin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
15
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

We analyzed this package on Nov 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/frame_view.dart. (-1 points)

Analysis of lib/frame_view.dart reported 2 hints:

line 46 col 3: Prefer using /// for doc comments.

line 53 col 3: Prefer using /// for doc comments.

Format lib/video_ad.dart.

Run flutter format to format lib/video_ad.dart.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/huamaomao/flutter_ad_plugin was unreachable.

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.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test