AppLovin / AppLovin-MAX-Flutter

MIT License
50 stars 28 forks source link

Feature Request: Prevent Banner Ad Reload on Widget Tree Changes #233

Open yo1106 opened 1 month ago

yo1106 commented 1 month ago

Feature Description

Description: Currently, when a MaxAdView for a banner ad is removed and then added back to the widget tree, it reloads the ad. This is particularly problematic for banner ads used in overlay or scrollable views, where the ad might frequently disappear and reappear. On slower devices, this can result in longer wait times and negatively impact the user experience. It's crucial to have an option to retain the banner ad's state and prevent it from reloading when the widget tree changes.

Use Case: In our application, we display banner ads as overlays that disappear upon user scrolling. When the same widget is displayed again, the ad reloads, which is inefficient. This is especially critical on lower-performance devices where ad reload times are significant.

Proposed Solution: Similar to AdMob's implementation in Flutter, we propose separating the advertisement object from the advertisement widget. This would allow the ad to maintain its state independently of the widget lifecycle.

AdMob Implementation Reference: AdMob allows creating a BannerAd object separately from the AdWidget that displays it. Once the ad is loaded, it can be displayed in any widget without needing to be reloaded, as exemplified in their documentation: AdMob Flutter Banner.

Example API Proposal:

// Create a BannerAd object
final BannerAd myBanner = BannerAd(
  adUnitId: 'YOUR_BANNER_AD_UNIT_ID',
  size: AdSize.banner,
  request: AdRequest(),
  listener: BannerAdListener(),
);

// Load the banner ad
myBanner.load();

// Use the BannerAd object in a widget
Widget bannerWidget = AdWidget(ad: myBanner);

Expected Behavior:

Provide a configuration to retain the banner ad state when the widget is removed and added back to the widget tree. The state of the banner ad should be preserved, avoiding unnecessary reloads and displaying the ad instantly upon re-adding.

Benefit:

Reduces redundant network requests and improves performance, particularly on slower devices. Provides a smoother user experience by ensuring that banner ads do not require reloading when navigating through different parts of the app.

alhiwatan commented 1 month ago

@yo1106, thank you for filing an RFE to avoid reloading banner widgets. We will consider adding it to our queue.