google_ads_helper 1.0.1 copy "google_ads_helper: ^1.0.1" to clipboard
google_ads_helper: ^1.0.1 copied to clipboard

A comprehensive Flutter plugin for Google Mobile Ads with easy integration, smart initialization, revenue tracking, and professional widgets.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:google_ads_helper/google_ads_helper.dart';

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

  // Initialize with test IDs for example
  await SimpleAdInitializer.initializeForRewardApp(
    rewardedAdUnitId: AdConstants.testRewardedAdUnitId,
    interstitialAdUnitId: AdConstants.testInterstitialAdUnitId,
  );

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Google Ads Helper Example',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: ExampleScreen(),
    );
  }
}

class ExampleScreen extends StatefulWidget {
  @override
  _ExampleScreenState createState() => _ExampleScreenState();
}

class _ExampleScreenState extends State<ExampleScreen> {
  int coins = 100;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Google Ads Helper Example'),
      ),
      body: Column(
        children: [
          // Banner Ad at top
          BannerAdWidget(
            height: 60,
            margin: EdgeInsets.all(10),
          ),

          Expanded(
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'Coins: $coins',
                    style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
                  ),

                  SizedBox(height: 40),

                  // Rewarded Ad Button
                  ElevatedButton(
                    onPressed: () {
                      AdHelper.showRewarded(
                        onRewardEarned: (reward) {
                          setState(() {
                            coins += 50;
                          });
                          ScaffoldMessenger.of(context).showSnackBar(
                            SnackBar(content: Text('Earned 50 coins!')),
                          );
                        },
                        onAdNotReady: () {
                          ScaffoldMessenger.of(context).showSnackBar(
                            SnackBar(content: Text('Ad not ready yet')),
                          );
                        },
                      );
                    },
                    child: Text('Watch Rewarded Ad (+50 coins)'),
                  ),

                  SizedBox(height: 20),

                  // Interstitial Ad Button
                  ElevatedButton(
                    onPressed: () {
                      AdHelper.showInterstitial(
                        onInterstitialShown: () {
                          print('Interstitial shown');
                        },
                        onAdClosed: () {
                          setState(() {
                            coins += 25;
                          });
                          ScaffoldMessenger.of(context).showSnackBar(
                            SnackBar(content: Text('Task completed! +25 coins')),
                          );
                        },
                      );
                    },
                    child: Text('Complete Task (+25 coins)'),
                  ),

                  SizedBox(height: 20),

                  // Show interstitial count
                  Text(
                    'Interstitial calls: ${AdHelper.interstitialCallCount}/3',
                    style: TextStyle(fontSize: 16),
                  ),

                  Text(
                    AdHelper.willInterstitialShowNext
                        ? 'Next call will show ad!'
                        : 'Ad will show after ${3 - AdHelper.interstitialCallCount} more calls',
                    style: TextStyle(fontSize: 14, color: Colors.grey[600]),
                  ),
                ],
              ),
            ),
          ),

          // Native Ad at bottom
          NativeAdWidget(
            height: 150,
            margin: EdgeInsets.all(10),
            borderRadius: BorderRadius.circular(10),
          ),
        ],
      ),
    );
  }
}
8
likes
130
points
19
downloads

Publisher

unverified uploader

Weekly Downloads

A comprehensive Flutter plugin for Google Mobile Ads with easy integration, smart initialization, revenue tracking, and professional widgets.

Homepage

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter, google_mobile_ads

More

Packages that depend on google_ads_helper

Packages that implement google_ads_helper