BlueStack SDK Flutter Plugin
A Flutter plugin for integrating BlueStack SDK in your Flutter applications. This plugin provides a comprehensive set of tools for displaying various types of ads including interstitial, rewarded, and banner ads.
Features
- SDK Initialization - Simple one-time initialization with debug mode support
- Interstitial Ads - Full-screen ads with comprehensive event handling
- Rewarded Ads - Video ads with reward callback support
- Banner Ads - Multiple banner sizes with automatic refresh support
- Debug Mode - Detailed logging and debugging capabilities
- Event Handling - Comprehensive callback system for ad lifecycle events
- Platform Support - Full support for both Android and iOS
Requirements
- Flutter: >=3.3.0
- Android: minSdkVersion 21
- iOS: iOS 11.0 or newer
Installation
Add this to your package's pubspec.yaml
file:
dependencies:
bluestack_sdk_flutter: ^1.0.0
Usage
Initialize the SDK
import 'package:bluestack_sdk_flutter/bluestack_sdk.dart';
// Set up initialization event listeners
BlueStackInitializer.setEventListener(InitializationEventListener(
onInitializationSuccess: (adapterStatus) {
print('SDK initialized successfully');
},
onInitializationFail: (error) {
print('SDK initialization failed: ${error.toString()}');
},
));
// Initialize the SDK
BlueStackInitializer.initialize(
appId: "YOUR_APP_ID",
enableDebug: true, // Set to false for production
);
Interstitial Ads
// Create an interstitial ad instance
final interstitialAd = InterstitialAd('/YOUR_APP_ID/interstitial');
// Set up load event listeners
interstitialAd.setLoadEventListener(InterstitialAdLoadEventListener(
onAdLoaded: () {
print('Interstitial ad loaded');
},
onAdFailedToLoad: (error) {
print('Interstitial ad failed to load: ${error.message}');
},
));
// Set up show event listeners
interstitialAd.setShowEventListener(InterstitialAdShowEventListener(
onAdDisplayed: () {
print('Interstitial ad displayed');
},
onAdFailedToDisplay: (error) {
print('Interstitial ad failed to display: ${error.message}');
},
onAdDismissed: () {
print('Interstitial ad dismissed');
},
onAdClicked: () {
print('Interstitial ad clicked');
},
));
// Load the ad
await interstitialAd.load();
// Show the ad
await interstitialAd.show();
// Don't forget to dispose when done
interstitialAd.dispose();
Rewarded Ads
// Create a rewarded ad instance
final rewardedAd = RewardedAd('/YOUR_APP_ID/rewardedVideo');
// Set up load event listeners
rewardedAd.setLoadEventListener(RewardedAdLoadEventListener(
onAdLoaded: () {
print('Rewarded ad loaded');
},
onAdFailedToLoad: (error) {
print('Rewarded ad failed to load: ${error.message}');
},
));
// Set up show event listeners
rewardedAd.setShowEventListener(RewardedAdShowEventListener(
onAdDisplayed: () {
print('Rewarded ad displayed');
},
onAdFailedToDisplay: (error) {
print('Rewarded ad failed to display: ${error.message}');
},
onAdDismissed: () {
print('Rewarded ad dismissed');
},
onAdClicked: () {
print('Rewarded ad clicked');
},
onRewarded: (reward) {
print('Rewarded: ${reward.type} - ${reward.amount}');
},
));
// Load the ad
await rewardedAd.load();
// Show the ad
await rewardedAd.show();
// Don't forget to dispose when done
rewardedAd.dispose();
Banner Ads
// Create a banner view
BannerView(
type: BannerAdSize.banner, // Choose from various sizes
placementId: '/YOUR_APP_ID/banner',
shouldLoadWhenReady: false,
options: options,
onAdLoaded: (size) {
print('Banner ad loaded with size: $size');
},
onAdFailedToLoad: (error) {
print('Banner ad failed to load: ${error.message}');
},
onAdClicked: () {
print('Banner ad clicked');
},
onAdRefreshed: () {
print('Banner ad refreshed');
},
onAdFailedToRefresh: (error) {
print('Banner ad failed to refresh: ${error.message}');
},
)
// Control banner visibility
bannerViewKey.currentState?.toggleVisibility(true);
// Control banner refresh
bannerViewKey.currentState?.toggleRefresh(true);
// Destroy banner when done
bannerViewKey.currentState?.destroy();
Available Banner Sizes
enum BannerAdSize {
banner, // 320x50
largeBanner, // 320x100
fullBanner, // 468x60
mediumRectangle, // 300x250
leaderboard, // 728x90
dynamicBanner, // width varies, height 50
dynamicLeaderboard // width varies, height 90
}
Request Options
You can customize ad requests using RequestOptions
:
final options = RequestOptions()
..setAge(25)
..setLanguage('en')
..setGender(Gender.unknown)
..setKeyword('test')
..setCustomParameters({
'key': 'value'
});
rewardedAd.load(options: options);
Example
Check the example
directory for a complete example app demonstrating all features.
License
This project is licensed under the MIT License - see the LICENSE file for details.