unity_ads_flutter 1.1.0

unity_ads_flutter #

Unity Ads for Flutter. This is an unofficial plugin based on the official Unity Ads plugins for Android and iOS.

Getting Started #

This plugin wraps the native Android and iOS APIs of Unity Ads. To learn more about the usage see the official Untiy Ads API Documentation for Android. Read CHANGELOG.md to see which versions of the native plugins are included.

[1.1.0] - 04.09.2018

Currently the following versions of the Unity Ads native plugins are used:

  • Android: 2.3.0
  • iOS: Nils told me that on iOS the newest version is used automatically

[1.0.0] - 11.05.2018

Currently the following versions of the Unity Ads native plugins are used:

  • Android: 2.2.1
  • iOS: 2.2.0

example/lib/main.dart

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

//TODO use your own ids from the Unity Ads Dashboard
const String videoPlacementId='video';
const String gameIdAndroid='1790451';
const String gameIdIOS='1790452';

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

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

class _MyAppState extends State<MyApp> with UnityAdsListener{

  UnityAdsError _error;
  String _errorMessage;
  bool _ready;

  @override
  initState() {
    UnityAdsFlutter.initialize(gameIdAndroid, gameIdIOS, this, true);
    _ready = false;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    Widget body;
      if(_error!=null){
        body = new Center(
            child: new Text('$_error: $_errorMessage')
        );
      } else if(_ready){
        body=new Center(
            child:new RaisedButton(
                onPressed: () {
                  setState((){
                    _ready=false;
                  });
                  UnityAdsFlutter.show('video');
                },
                child: const Text('Ready')
            )
        );
      } else {
        body = new Center(
            child:const Text('Waiting for an ad...')
        );
      }
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Unity Ads Flutter Example'),
        ),
        body: body,
      ),
    );
  }

  @override
  void onUnityAdsError(UnityAdsError error, String message) {
    print('$error occurred: $message');
    setState((){
      _error=error;
      _errorMessage=message;
    });
  }

  @override
  void onUnityAdsFinish(String placementId, FinishState result) {
    print('Finished $placementId with $result');
  }

  @override
  void onUnityAdsReady(String placementId) {
    print('Ready: $placementId');
    if (placementId == videoPlacementId){
      setState(() {
        _ready=true;
      });
    }
  }

  @override
  void onUnityAdsStart(String placementId) {
    print('Start: $placementId');
    if(placementId == videoPlacementId){
      setState(() {
        _ready = false;
      });
    }
  }
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

47 out of 47 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/unity_ads_flutter.dart.

Run flutter format to format lib/unity_ads_flutter.dart.

Maintenance suggestions

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.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8