0

I wanted to add some Admob Banner in my Flutter app (using the offical Admob package https://pub.dev/packages/google_mobile_ads)

Flutter Admob guide only provide 1 Test ID for iOS and another for Android, what can I do if I need multiple Test ID in my app?

Calvin
  • 321
  • 2
  • 16

2 Answers2

0

You can use the same Test ID multiple times. But make sure to replace it with a real one before launching. Real ones cannot be called multiple times (unless if you dispose them before using them somewhere else) so create new ones accordingly

YaDev
  • 33
  • 1
  • 6
  • It is not possible in my case. I am adding my Banner ads into my ListView and Flutter is flagging error when I use the same ads in multiple ListView index (similar case is filed here: https://stackoverflow.com/questions/66899247/flutter-this-adwidget-is-already-in-the-widget-tree-how-to-disable-this-exce). One of the common suggestion is to use a different ID, so I wanted to test this out. – Calvin Mar 18 '22 at 14:01
  • Oh I get you, I'm guessing your using the same bannerAd instance? If so you need to create a different instance. Using the same instance in multiple places is not permitted. – YaDev Mar 18 '22 at 15:48
  • I tried using different instances with the same ID, and have these 2 instances used in 2 different index in ListView. But Flutter is still flagging the same error. Therefore I wanted to try 2 different Test ID in Flutter instead. – Calvin Mar 18 '22 at 23:11
  • are you trying to achieve infinite scrolling with inline banner ads? – YaDev Mar 19 '22 at 12:29
0

Finally found the solution. I have summarised the steps below for anyone who wants to know how to use multiple IDs in Flutter (this might be common since Flutter users is likely to place Ads in ListView). I have also added some reading reference below.

In summary:

  • Use your own Ads Id (not Test Id)
  • Run an Ads in your actual Device to obtain the Test Device ID. This is automatically print out when the ads is called. Find the text similar to the example shown below:

RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("The code you want to copy")) to get test ads on this device."

  • Use the code below to initialised Admob to provide Test Ads. Call the code before you initialised Admob.
  • You will observe actual Ads but with a "Test Ads" text on top.

Code to initialised Test Ads for Flutter:

//"The code you want to copy" is the code that you extract from your log based on earlier steps
List<String> testDeviceIds = "The code you want to copy";

RequestConfiguration configuration = RequestConfiguration(
    testDeviceIds: testDeviceIds);
MobileAds.instance.updateRequestConfiguration(configuration);

Reading material for reference:

Reference to Admob Test Ads for native Android if you are interested - link. They should add documentation for Flutter.

Reference to the code from another post which provide the code by answering a different question. Here is the link.

Calvin
  • 321
  • 2
  • 16