ad_flow 1.0.0+2
ad_flow: ^1.0.0+2 copied to clipboard
Easy AdMob integration for Flutter. Banner, interstitial, native & app open ads with 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 'demo_home_page.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize the ad service
// This handles: consent, SDK init, and optional preloading
await AdService.instance.initialize(
onComplete: (canRequestAds) {
debugPrint('═══════════════════════════════════════════');
debugPrint('AdService initialized!');
debugPrint('Can request ads: $canRequestAds');
debugPrint('Ads enabled: ${AdService.instance.isAdsEnabled}');
debugPrint('═══════════════════════════════════════════');
},
preloadInterstitial: true,
preloadAppOpen: true,
showAppOpenOnColdStart: false, // Disable for demo so user can see the app first
enableAppOpenOnForeground: true,
maxForegroundAdsPerSession: 2,
);
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(),
);
}
}