Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Fix Dart 2 type errors in firebase_admob (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
mravn-google committed Mar 1, 2018
1 parent 915e260 commit 61bd006
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
6 changes: 5 additions & 1 deletion packages/firebase_admob/CHANGELOG.md
@@ -1,3 +1,7 @@
## 0.3.2

* Fixed Dart 2 type errors.

## 0.3.1

* Enabled use in Swift projects.
Expand All @@ -8,7 +12,7 @@
* **Breaking change**. The properties and parameters named "unitId" in BannerAd
and InterstitialAd have been renamed to "adUnitId" to better match AdMob's
documentation and UI.

## 0.2.3

* Simplified and upgraded Android project template to Android SDK 27.
Expand Down
28 changes: 16 additions & 12 deletions packages/firebase_admob/lib/firebase_admob.dart
Expand Up @@ -118,8 +118,6 @@ abstract class MobileAd {
/// Plugin log messages will identify this property as the ad's `mobileAdId`.
int get id => hashCode;

MethodChannel get _channel => FirebaseAdMob.instance._channel;

/// Start loading this ad.
Future<bool> load();

Expand All @@ -131,21 +129,21 @@ abstract class MobileAd {
/// The [listener] will be notified when the ad has finished loading or fails
/// to do so. An ad that fails to load will not be shown.
Future<bool> show() {
return _channel.invokeMethod("showAd", <String, dynamic>{'id': id});
return _invokeBooleanMethod("showAd", <String, dynamic>{'id': id});
}

/// Free the plugin resources associated with this ad.
///
/// Disposing a banner ad that's been shown removes it from the screen. Interstitial
/// ads can't be programatically removed from view.
/// Disposing a banner ad that's been shown removes it from the screen.
/// Interstitial ads can't be programmatically removed from view.
Future<bool> dispose() {
assert(_allAds[id] != null);
_allAds[id] = null;
return _channel.invokeMethod("disposeAd", <String, dynamic>{'id': id});
return _invokeBooleanMethod("disposeAd", <String, dynamic>{'id': id});
}

Future<bool> _doLoad(String loadMethod) {
return _channel.invokeMethod(loadMethod, <String, dynamic>{
return _invokeBooleanMethod(loadMethod, <String, dynamic>{
'id': id,
'adUnitId': adUnitId,
'targetingInfo': targetingInfo?.toJson(),
Expand Down Expand Up @@ -278,18 +276,16 @@ class RewardedVideoAd {
/// Callback invoked for events in the rewarded video ad lifecycle.
RewardedVideoAdListener listener;

MethodChannel get _channel => FirebaseAdMob.instance._channel;

/// Shows a rewarded video ad if one has been loaded.
Future<bool> show() {
return _channel.invokeMethod("showRewardedVideoAd");
return _invokeBooleanMethod("showRewardedVideoAd");
}

/// Loads a rewarded video ad using the provided ad unit ID.
Future<bool> load(
{@required String adUnitId, MobileAdTargetingInfo targetingInfo}) {
assert(adUnitId.isNotEmpty);
return _channel.invokeMethod("loadRewardedVideoAd", <String, dynamic>{
return _invokeBooleanMethod("loadRewardedVideoAd", <String, dynamic>{
'adUnitId': adUnitId,
'targetingInfo': targetingInfo?.toJson(),
});
Expand Down Expand Up @@ -369,7 +365,7 @@ class FirebaseAdMob {
bool analyticsEnabled: false}) {
assert(appId != null && appId.isNotEmpty);
assert(analyticsEnabled != null);
return _channel.invokeMethod("initialize", <String, dynamic>{
return _invokeBooleanMethod("initialize", <String, dynamic>{
'appId': appId,
'trackingId': trackingId,
'analyticsEnabled': analyticsEnabled,
Expand Down Expand Up @@ -405,3 +401,11 @@ class FirebaseAdMob {
return new Future<Null>(null);
}
}

Future<bool> _invokeBooleanMethod(String method, [dynamic arguments]) async {
final bool result = await FirebaseAdMob.instance._channel.invokeMethod(
method,
arguments,
);
return result;
}
2 changes: 1 addition & 1 deletion packages/firebase_admob/pubspec.yaml
@@ -1,6 +1,6 @@
name: firebase_admob
description: Firebase AdMob plugin for Flutter applications.
version: 0.3.1
version: 0.3.2
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_admob

Expand Down

0 comments on commit 61bd006

Please sign in to comment.