flutter_ad_plugin 1.1.1
flutter_ad_plugin: ^1.1.1 copied to clipboard

ad sdk.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:flutter_ad_plugin/video_ad.dart';
import 'package:flutter_ad_plugin/frame_view.dart';
import 'package:permission_handler/permission_handler.dart';

 var gdtAppId="1101152570";
void main() async{
   runApp(MaterialApp(home: MyApp(),
       routes: <String, WidgetBuilder> {
         '/screen1': (BuildContext context) =>  FirstScreen(),
         '/screen2': (BuildContext context) =>  FirstScreen1(),
       }
   ));
}

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



Widget buildAdView(){
  return new Container(
    child: new UiKitView(viewType: "AdView"),
  );
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

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

  static const MethodChannel ios_channel = const MethodChannel('hua.ad.ios');

  @override
  void initState() {
    eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);
    super.initState();
    requestPermiss();
   //sdk init
    VideoAd.initAdCsj({"code":"5001121","name":"APP测试媒体"});
    VideoAd.initAdBaidu("e866cfb0");
    //VideoAd.initAdGdt("d3bdb4cf-e72b-4040-9439-9856020fbe8b");
    //激励视频初始化
     VideoAd.initVieo("901121365");
    VideoAd.initVieoBaidu("5925490");

   // var version=platformVersion;
   // print("platformVersion=$version");
   /* Scaffold.of(context).showSnackBar(
      new SnackBar(
        content: new Text("   $version"),
        action: new SnackBarAction(
          label: "UNDO",
          onPressed: () => Scaffold.of(context).hideCurrentSnackBar(),
        ),
      ),
    );*/

  }

  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');
    }

  }


/*  static Future<String> get platformVersion async {
    final String version = await testChannel.invokeMethod('getPlatformVersion');
    return version;
  }*/

  static Future<int> requestNativeAdd(int x, int y) async {
    int result = await ios_channel.invokeMethod('add', {"x": x, "y": y});
    print("requestNativeAdd=$result");
    return result;
  }



  void _onEvent(Object event) {
    print("_onEvent  $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) {

  }


  @override
  Widget build(BuildContext context) {
    return MaterialApp(

      home: Scaffold(
        body:  Center(
          child: buildAdView(),
        ),//Text("申请权限。。。")

      )
    );
  }
}

class FirstScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('feedAD'),
      ),
      body: new Center(
        child: FrameView(onFrameViewCreated: _onFrameViewCreated,)
      ),
    );
  }


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

    // controller.loadSplashAdGdt(gdtAppId,'8863364436303842593');
  }

}
class FirstScreen1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('feedAD'),
      ),
      body:  Column(children: <Widget>[
        Container(
            child: FrameView(onFrameViewCreated: _onFrameViewCreated,),
            height: 400,
            //width: 600,
        ),
        Container(
          child: FrameView(onFrameViewCreated: _onFrameViewCreated2,),
          height: 140,
          //width: 600,
        ),
        Center(child: GestureDetector(child:Text("看20分钟视频",),onTap: showAd,),)

      ],),
    );
  }


  void showAd(){
     //激励视频显示
    // VideoAd.showVieo();
     VideoAd.showVieoBaidu();
  }

  void _onFrameViewCreated(FrameViewController controller) {
    //穿山甲  feed广告  广告id
   controller.loadFeedAdCsj("901121737");
    //百度    广告id
   controller.loadFeedAdBaidu("2058628");


  }

  void _onFrameViewCreated2(FrameViewController controller) {
    //穿山甲   nativebanner 广告id
   // controller.loadNativeAd("901121423");
    //百度   nativebanner 广告id
    controller.loadBannerBaidu('2015351');
  }



}