flutter_yandex_ads 1.0.5 copy "flutter_yandex_ads: ^1.0.5" to clipboard
flutter_yandex_ads: ^1.0.5 copied to clipboard

Yandex Ads support for flutter applications.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_yandex_ads/components/appopen.dart';
import 'package:flutter_yandex_ads/components/banner.dart';
import 'package:flutter_yandex_ads/components/interstitial.dart';
import 'package:flutter_yandex_ads/components/rewarded.dart';
import 'package:flutter_yandex_ads/pigeons/appopen.dart';
import 'package:flutter_yandex_ads/pigeons/banner.dart';
import 'package:flutter_yandex_ads/pigeons/interstitial.dart';
import 'package:flutter_yandex_ads/pigeons/native.dart';
import 'package:flutter_yandex_ads/pigeons/rewarded.dart';
import 'package:flutter_yandex_ads/widgets/banner.dart';
import 'package:flutter_yandex_ads/widgets/native.dart';
import 'package:flutter_yandex_ads/yandex.dart';

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

class App extends StatefulWidget {
  const App({Key? key}) : super(key: key);

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  void initState() {
    super.initState();

    FlutterYandexAds.initialize();

    YandexAdsAppOpenComponent(
      id: "demo-appopenad-yandex",
      onAdLoaded: () {
        print('appopen onAdLoaded');
      },
      onAdFailedToLoad: (InterstitialError err) {
        print('appopen onAdFailedToLoad code: ${err.code}, description: ${err.description}');
      },
      onAdFailedToShow: (InterstitialError err) {
        print('appopen onAdFailedToShow description: ${err.description}');
      },
      onAdDismissed: () {
        print("appopen onAdDismissed");
      },
      onAdShown: () {
        print("appopen onAdShown");
      },
      onImpression: (AppOpenImpression? data) {
        print('appopen onImpression ${data?.data}');
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 4,
        child: SafeArea(
          child: Scaffold(
            appBar: AppBar(
              title: const Text('Yandex ADS'),
            ),
            bottomNavigationBar: const TabBar(
              tabs: [
                Tab(child: Text('Banner', style: TextStyle(color: Colors.black54, fontSize: 12))),
                Tab(child: Text('Interstitial', style: TextStyle(color: Colors.black54, fontSize: 12))),
                Tab(child: Text('Native', style: TextStyle(color: Colors.black54, fontSize: 12))),
                Tab(child: Text('Rewarded', style: TextStyle(color: Colors.black54, fontSize: 12))),
              ],
            ),
            body: const TabBarView(
              children: [
                BannerScreen(),
                InterstitialScreen(),
                NativeScreen(),
                RewardedScreen(),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class BannerScreen extends StatefulWidget {
  const BannerScreen({Key? key}) : super(key: key);

  @override
  _BannerScreenState createState() => _BannerScreenState();
}

class _BannerScreenState extends State<BannerScreen> {
  late YandexAdsBannerComponent banner;

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

    banner = YandexAdsBannerComponent(
      width: 320,
      height: 100,
      id: 'demo-banner-yandex',
      onAdLoaded: () {
        print('banner onAdLoaded');
      },
      onAdFailedToLoad: (BannerError err) {
        print('banner onAdFailedToLoad code: ${err.code}, description: ${err.description}');
      },
      onImpression: (BannerImpression? data) {
        print("banner onImpression ${data?.data}");
      },
      onAdClicked: () {
        print('banner onAdClicked');
      },
    );

    banner.load();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        const Text('Banner'),
        SizedBox(
          height: 100,
          child: YandexAdsBannerWidget(
            banner: banner,
          ),
        ),
      ],
    );
  }
}

class NativeScreen extends StatefulWidget {
  const NativeScreen({Key? key}) : super(key: key);

  @override
  State<NativeScreen> createState() => _NativeScreenState();
}

class _NativeScreenState extends State<NativeScreen> {
  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        const Text('Native'),
        SizedBox(
          height: 300,
          child: YandexAdsNativeWidget(
            id: 'demo-native-app-yandex',
            onAdLoaded: () {
              print('native onAdLoaded');
            },
            onAdFailedToLoad: (BannerError err) {
              print('native onAdFailedToLoad code: ${err.code}, description: ${err.description}');
            },
            onImpression: (NativeImpression? data) {
              print("native onImpression ${data?.data}");
            },
            onAdClicked: () {
              print('native onAdClicked');
            },
          ),
        ),
      ],
    );
  }
}

class InterstitialScreen extends StatefulWidget {
  const InterstitialScreen({Key? key}) : super(key: key);

  @override
  _InterstitialScreenState createState() => _InterstitialScreenState();
}

class _InterstitialScreenState extends State<InterstitialScreen> {
  late YandexAdsInterstitialComponent interstitial;

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

    interstitial = YandexAdsInterstitialComponent(
      id: 'demo-interstitial-yandex',
      onAdLoaded: () {
        print('interstitial onAdLoaded');
      },
      onAdFailedToLoad: (InterstitialError err) {
        print('interstitial onAdFailedToLoad code: ${err.code}, description: ${err.description}');
      },
      onAdFailedToShow: (InterstitialError err) {
        print('interstitial onAdFailedToShow description: ${err.description}');
      },
      onAdDismissed: () {
        print("interstitial onAdDismissed");
      },
      onAdShown: () {
        print("interstitial onAdShown");
      },
      onImpression: (InterstitialImpression? data) {
        print('interstitial onImpression ${data?.data}');
      },
    );

    interstitial.load();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        const Text('Interstitial'),
        ElevatedButton(
          onPressed: () {
            interstitial.show();
          },
          child: const Text('show'),
        ),
      ],
    );
  }
}

class RewardedScreen extends StatefulWidget {
  const RewardedScreen({Key? key}) : super(key: key);

  @override
  State<RewardedScreen> createState() => _RewardedScreenState();
}

class _RewardedScreenState extends State<RewardedScreen> {
  late YandexAdsRewardedComponent rewarded;

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

    rewarded = YandexAdsRewardedComponent(
        id: 'demo-rewarded-yandex',
        onAdLoaded: () {
          print('rewarded onAdLoaded');
        },
        onAdFailedToLoad: (RewardedError err) {
          print('rewarded onAdFailedToLoad code: ${err.code}, description: ${err.description}');
        },
        onAdFailedToShow: (RewardedError err) {
          print('rewarded onAdFailedToShow description: ${err.description}');
        },
        onAdDismissed: () {
          print("rewarded onAdDismissed");
        },
        onAdShown: () {
          print("rewarded onAdShown");
        },
        onImpression: (RewardedImpression? data) {
          print('rewarded onImpression ${data?.data}');
        },
        onRewarded: (RewardedEvent? data) {
          print('rewarded onRewarded amount ${data?.amount}, type ${data?.type}');
        });

    rewarded.load();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        const Text('Rewarded'),
        ElevatedButton(
          onPressed: () {
            rewarded.show();
          },
          child: const Text('show'),
        ),
      ],
    );
  }
}
28
likes
95
pub points
59%
popularity

Publisher

verified publisherkovardin.ru

Yandex Ads support for flutter applications.

Homepage

Documentation

API reference

License

WTFPL (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_yandex_ads