A Flutter package for integrating AddStream ads into your mobile applications. To learn more about AddStream, please visit the AddStream website
β¨ Easy Integration - Simple widget-based API
π― Multiple Ad Formats - Support for image and GIF ads
β‘ Fast & Lightweight - Minimal dependencies
π Private & Secure - Uses HMAC-SHA256 signature for authentication
π± Cross-Platform - Works on iOS and Android
π¨ Customizable - Custom loading and error widgets
Add this to your pubspec.yaml:
dependencies:
addstream_flutter: ^1.0.0Then run:
flutter pub getAdd the following to your android/app/src/main/AndroidManifest.xml inside the <application> tag:
<!-- Provide required visibility configuration for API level 30 and above -->
<queries>
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
</queries>Add the following to your ios/Runner/Info.plist:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
<string>http</string>
</array>In your main.dart, initialize AddStream before running your app:
import 'package:flutter/material.dart';
import 'package:addstream_flutter/addstream_flutter.dart';
void main() {
// Initialize AddStream
AddStreamGlobal.initialize(
AddStreamConfig(
apiUrl: 'https://your-api-url.com',
apiKey: 'your-api-key-here',
),
);
runApp(MyApp());
}Add the AddStreamWidget anywhere in your app:
AddStreamWidget(
zoneId: 'your-zone-id',
width: 320,
height: 50,
margin: const EdgeInsets.all(16),
borderRadius: 12,
onAdLoaded: () => print('Ad loaded!'),
onAdFailed: (error) => print('Error: $error'),
)class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('My App')),
body: Column(
children: [
Expanded(
child: Center(child: Text('Your content here')),
),
// Banner ad at the bottom
AddStreamWidget(
zoneId: '123',
width: 320,
height: 50,
),
],
),
);
}
}AddStreamWidget(
zoneId: '123',
width: 300,
height: 250,
loadingWidget: Center(
child: CircularProgressIndicator(),
),
errorWidget: Container(
padding: EdgeInsets.all(16),
child: Text('Ad not available'),
),
onAdLoaded: () {
print('Ad successfully loaded');
},
onAdFailed: (error) {
print('Failed to load ad: $error');
},
)AddStreamWidget(
zoneId: '123',
width: 320,
height: 100,
onAdLoaded: () {
// Track analytics
analytics.logEvent('ad_loaded');
},
onAdFailed: (error) {
// Handle error
if (error is AddStreamException) {
showErrorDialog(error.message);
}
},
)Initializes the AddStream SDK. Must be called before using any widgets.
Parameters:
config(AddStreamConfig): Configuration object
Example:
AddStreamGlobal.initialize(
AddStreamConfig(
apiUrl: 'https://your-api-url.com',
apiKey: 'your-key',
timeout: Duration(seconds: 10),
),
);Main widget for displaying ads.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
zoneId |
String | Yes | Your ad zone ID |
width |
double? | No | Ad width (default: 400) |
height |
double? | No | Ad height (default: 100) |
margin |
EdgeInsetsGeometry? | No | Ad margin (default: null) |
borderRadius |
double | No | Ad circular border radius (default: 12.0) |
onAdLoaded |
VoidCallback? | No | Called when ad loads successfully |
onAdFailed |
Function(Object)? | No | Called when ad fails to load |
loadingWidget |
Widget? | No | Custom loading widget |
errorWidget |
Widget? | No | Custom error widget |
Configuration object for initialization.
Properties:
apiUrl(String): Base UrlapiKey(String): API keytimeout(Duration): Request timeout (default: 10 seconds)
Custom exception class for AddStream errors.
Properties:
message(String): Error messageoriginalError(dynamic): Original error if any
The package handles errors gracefully and provides multiple ways to handle them:
// Option 1: Using callback
AddStreamWidget(
zoneId: '123',
onAdFailed: (error) {
if (error is AddStreamException) {
print('AddStream error: ${error.message}');
}
},
)
// Option 2: Try-catch (for initialization)
try {
AddStreamGlobal.initialize(config);
} on AddStreamException catch (e) {
print('Failed to initialize: ${e.message}');
}Make sure you've initialized AddStream:
AddStreamGlobal.initialize(AddStreamConfig(apiUrl: '...', apiKey: '...'));Call AddStreamGlobal.initialize() before using any widgets, typically in your main() function.
This is normal when there's no ad inventory for your zone. The widget will show the errorWidget or hide itself.
- Flutter: >=3.0.0
- Dart: >=3.0.0
http: ^1.1.0html: ^0.15.4url_launcher: ^6.2.0crypto: ^3.0.6
This package is proprietary software. See LICENSE for details.
See CHANGELOG.md for version history.