From 97b0000a98b7f13cdc1348177ff494c3c1f206f0 Mon Sep 17 00:00:00 2001 From: Bruno Stone Date: Mon, 10 Feb 2020 17:46:38 -0300 Subject: [PATCH] prevent ads from being reloaded (#129) --- lib/src/admob_banner.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/admob_banner.dart b/lib/src/admob_banner.dart index 26ed4c3..68eb6c0 100644 --- a/lib/src/admob_banner.dart +++ b/lib/src/admob_banner.dart @@ -24,6 +24,7 @@ class AdmobBanner extends StatefulWidget { } class _AdmobBannerState extends State { + UniqueKey _key = UniqueKey(); AdmobBannerController _controller; @override @@ -33,28 +34,28 @@ class _AdmobBannerState extends State { width: widget.adSize.width >= 0 ? widget.adSize.width.toDouble() : double.infinity, height: widget.adSize.height >= 0 ? widget.adSize.height.toDouble() : double.infinity, child: AndroidView( - key: UniqueKey(), + key: _key, viewType: 'admob_flutter/banner', creationParams: { "adUnitId": widget.adUnitId, "adSize": widget.adSize.toMap, }, - creationParamsCodec: StandardMessageCodec(), + creationParamsCodec: const StandardMessageCodec(), onPlatformViewCreated: _onPlatformViewCreated, ), ); } else if (defaultTargetPlatform == TargetPlatform.iOS) { return Container( - key: UniqueKey(), width: widget.adSize.width.toDouble(), height: widget.adSize.height.toDouble(), child: UiKitView( + key: _key, viewType: 'admob_flutter/banner', creationParams: { "adUnitId": widget.adUnitId, "adSize": widget.adSize.toMap, }, - creationParamsCodec: StandardMessageCodec(), + creationParamsCodec: const StandardMessageCodec(), onPlatformViewCreated: _onPlatformViewCreated, ), );