Flutter Ads SDK Initialization Example

View on Pub.dev

Learn how to initialize the Flutter Ads SDK in your app. This step-by-step guide shows how to set up ads in Flutter, including authentication, routing, and traffic validation for mobile, web, and desktop apps.

This Flutter Ads SDK initialization example helps developers integrate ads in Flutter apps with proper setup for routing, targeting, and validation.

How Initialization Works

Before loading ads, the Flutter Ads SDK must be initialized to enable authentication, routing, and traffic validation across mobile, web, and desktop environments.

1. Import Flutter Ads SDK

import 'package:flutter_ads_sdk/flutter_ads_sdk.dart';
      

2. Initialize Flutter Ads SDK

Call initialization once at app startup (e.g., in main or before UI render).

  
void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await FlutterAds.instance.ensureInitialized(
    appId: 'YOUR_APP_ID',
    apiKey: 'YOUR_API_KEY',
    sdkSecret: 'YOUR_SDK_SECRET',
  );

  runApp(const MyApp());
}
  
      

3. Auto Fetch (Optional)

Enable auto fetch to let the SDK handle ad requests automatically based on context and inventory levels.

FlutterAds.instance.enableAutoFetch(context);

When auto fetch is enabled:

4. Ready to Load Ads

After initialization, you can safely fetch and render ads anywhere in your app.

Make sure initialization is completed before requesting ads to avoid errors.

Next Steps