flutter_ad_plugin 1.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 42

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



}

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]
0
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]
42
Learn more about scoring.

We analyzed this package on Mar 31, 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

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.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test