ad_flow 1.3.0
ad_flow: ^1.3.0 copied to clipboard
Easy AdMob integration for Flutter with banner, interstitial, rewarded, native & app open ads, plus built-in GDPR/ATT consent management.
example/lib/main.dart
// Copyright 2024 - AdMob Integration Demo
// Production-ready example demonstrating all ad features
import 'package:flutter/material.dart';
import 'package:ad_flow/ad_flow.dart';
import 'pages/demo_home_page.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize the ad service with test mode configuration
// For production, use AdFlowConfig() with your real ad unit IDs:
//
// config: AdFlowConfig(
// androidBannerAdUnitId: 'ca-app-pub-YOUR_ID/BANNER_ID',
// iosBannerAdUnitId: 'ca-app-pub-YOUR_ID/BANNER_ID',
// androidInterstitialAdUnitId: 'ca-app-pub-YOUR_ID/INTERSTITIAL_ID',
// iosInterstitialAdUnitId: 'ca-app-pub-YOUR_ID/INTERSTITIAL_ID',
// // ... other ad unit IDs
// ),
await AdFlow.instance.initialize(
config: AdFlowConfig.testMode(), // Use Google's test ad IDs
onComplete: (canRequestAds) {
debugPrint('═══════════════════════════════════════════');
debugPrint('AdFlow initialized!');
debugPrint('Can request ads: $canRequestAds');
debugPrint('Ads enabled: ${AdFlow.instance.isAdsEnabled}');
debugPrint('═══════════════════════════════════════════');
},
preloadInterstitial: true,
preloadAppOpen: true,
showAppOpenOnColdStart: true,
enableAppOpenOnForeground: false,
maxForegroundAdsPerSession: 1,
);
runApp(const AdDemoApp());
}
class AdDemoApp extends StatelessWidget {
const AdDemoApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'AdMob Integration Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.indigo,
brightness: Brightness.light,
),
useMaterial3: true,
cardTheme: const CardThemeData(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(16)),
),
),
filledButtonTheme: FilledButtonThemeData(
style: FilledButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 14),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
darkTheme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.indigo,
brightness: Brightness.dark,
),
useMaterial3: true,
),
home: const DemoHomePage(),
);
}
}