adrop_ads_flutter 0.1.1 copy "adrop_ads_flutter: ^0.1.1" to clipboard
adrop_ads_flutter: ^0.1.1 copied to clipboard

AdropAds flutter plugin that shows ads using native platform views

example/lib/main.dart

import 'dart:async';

import 'package:adrop_ads_flutter/adrop_ads_flutter.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late final AdropBannerController _bannerController;

  @override
  void initState() {
    super.initState();
    initialize();
  }

  Future<void> initialize() async {
    await AdropAdsFlutter.initialize(true);
  }

  void _onAdropBannerCreated(AdropBannerController controller) {
    _bannerController = controller;
  }

  String getUnitId() {
    switch (defaultTargetPlatform) {
      case TargetPlatform.android:
        return "01HD5R49SJGY7KKEP9MK8DYEN7";
      case TargetPlatform.iOS:
        return "01HD5R54R6TDK91Y78M0J0SVCV";
      default:
        return "";
    }
  }

  @override
  Widget build(BuildContext context) {
    final screenWidth = MediaQuery.of(context).size.width;

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Hello, Adrop Ads!'),
        ),
        body: SafeArea(
          child: Column(
            children: [
              TextButton(
                  onPressed: () {
                    _bannerController.load();
                  },
                  child: const Text('Request Ad!')),
              const Spacer(),
              SizedBox(
                width: screenWidth,
                height: 80,
                child: AdropBanner(
                  onAdropBannerCreated: _onAdropBannerCreated,
                  unitId: getUnitId(),
                  adSize: AdropBannerSize.h80,
                  onAdClicked: () {
                    debugPrint("onAdClicked");
                  },
                  onAdReceived: () {
                    debugPrint("onAdReceived");
                  },
                  onAdFailedToReceive: (code) {
                    debugPrint("onAdFailedToReceive: $code");
                  },
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
0
points
218
downloads

Publisher

verified publisheradrop.io

Weekly Downloads

AdropAds flutter plugin that shows ads using native platform views

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on adrop_ads_flutter