Skip to content

Commit

Permalink
-- keepAlive
Browse files Browse the repository at this point in the history
  • Loading branch information
SachinGanesh committed Jun 7, 2019
1 parent cfb32d2 commit d29d594
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/ad/ad_banner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class FacebookBannerAd extends StatefulWidget {
/// Banner Ad listener
final void Function(BannerAdResult, dynamic) listener;

/// This defines if the ad view to be kept alive.
final bool keepAlive;

/// This widget is used to contain Banner Ads. [listener] is used to monitor
/// Banner Ad. [BannerAdResult] is passed to the callback function along with
/// other information based on result such as placement id, error code, error
Expand All @@ -70,15 +73,20 @@ class FacebookBannerAd extends StatefulWidget {
this.placementId = "YOUR_PLACEMENT_ID",
this.bannerSize = BannerSize.STANDARD,
this.listener,
this.keepAlive = false,
}) : super(key: key);

@override
_FacebookBannerAdState createState() => _FacebookBannerAdState();
}

class _FacebookBannerAdState extends State<FacebookBannerAd> {
class _FacebookBannerAdState extends State<FacebookBannerAd>
with AutomaticKeepAliveClientMixin {
double containerHeight = 0.5;

@override
bool get wantKeepAlive => widget.keepAlive;

@override
Widget build(BuildContext context) {
if (defaultTargetPlatform == TargetPlatform.android) {
Expand Down Expand Up @@ -112,7 +120,8 @@ class _FacebookBannerAdState extends State<FacebookBannerAd> {
? double.infinity
: widget.bannerSize.height.toDouble(),
child: Center(
child: Text("Banner Ads for this platform is currently not supported"),
child:
Text("Banner Ads for this platform is currently not supported"),
),
);
}
Expand Down
12 changes: 11 additions & 1 deletion lib/ad/ad_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class FacebookNativeAd extends StatefulWidget {
/// This defines the button border color of the Native Ad.
final Color buttonBorderColor;

/// This defines if the ad view to be kept alive.
final bool keepAlive;

/// This widget can be used to display customizable native ads and native
/// banner ads.
FacebookNativeAd({
Expand All @@ -103,14 +106,21 @@ class FacebookNativeAd extends StatefulWidget {
this.buttonColor,
this.buttonTitleColor,
this.buttonBorderColor,
this.keepAlive = false,
}) : super(key: key);

@override
_FacebookNativeAdState createState() => _FacebookNativeAdState();
}

class _FacebookNativeAdState extends State<FacebookNativeAd> {
class _FacebookNativeAdState extends State<FacebookNativeAd>
with AutomaticKeepAliveClientMixin {
double containerHeight = 0.5;
// bool keepAlive = false;

@override
bool get wantKeepAlive => widget.keepAlive;

@override
Widget build(BuildContext context) {
if (defaultTargetPlatform == TargetPlatform.android) {
Expand Down

0 comments on commit d29d594

Please sign in to comment.