Gabeloooooo
Gabeloooooo

Reputation: 675

Flutter Admob AppID use Android or iOS?

When we make an AdMob app in the admob console, we have a choice of Android or iOS apps. That means 2 different IDs.

Which one should we use in the Flutter AdMob plugin?

FirebaseAdMob.instance.initialize(appId: appId);

Upvotes: 11

Views: 1805

Answers (1)

Ganessa
Ganessa

Reputation: 882

How about setting as follows?

import 'dart:io';

  FirebaseAdMob.instance.initialize(
    appId: Platform.isAndroid
        ? 'ca-app-pub-NNNNNNNNNNNNNNNN~NNNNNNNNNN'
        : 'ca-app-pub-MMMMMMMMMMMMMMMM~MMMMMMMMMM',
  );

If you dislike conditional operators you can set as follows.

import 'dart:io';

  var appId;
  if (Platform.isAndroid) {
    appId = 'ca-app-pub-NNNNNNNNNNNNNNNN~NNNNNNNNNN';
  } else {
    appId = 'ca-app-pub-MMMMMMMMMMMMMMMM~MMMMMMMMMM';
  }
  FirebaseAdMob.instance.initialize(appId: appId);

Upvotes: 17

Related Questions