gns_flutter_plugin 0.0.3 copy "gns_flutter_plugin: ^0.0.3" to clipboard
gns_flutter_plugin: ^0.0.3 copied to clipboard

Geniee SDK for Flutter platform

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:gns_flutter_plugin/gns_flutter_plugin.dart';

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

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

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

class _MyAppState extends State<MyApp>
    implements FullscreenInterstitialListener {
  final FullscreenInterstitial fullscreenInterstitial =
      FullscreenInterstitial("1530756");

  bool _isInterstitialAdLoaded = false;

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

    _initialize();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {}

  Future<void> _initialize() async {
    try {
      await fullscreenInterstitial.initialize();
      fullscreenInterstitial.setListener(this);
    } catch (e) {}
  }

  Future<void> _loadAd() async {
    try {
      await fullscreenInterstitial.load();
      setState(() {
        _isInterstitialAdLoaded = false;
      });
    } catch (e) {}
  }

  Future<void> _showAd() async {
    try {
      await fullscreenInterstitial.show();
    } catch (e) {}
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
          children: [
            Column(
              children: [
                Container(
                  margin: const EdgeInsets.all(10),
                  child: const Text(
                    "Banner with RTB",
                    style: TextStyle(
                        fontSize: 28,
                        fontWeight: FontWeight.bold,
                        color: Colors.blueAccent),
                  ),
                ),
                Card(
                  child: SizedBox(
                    width: 300,
                    height: 250,
                    child: GNBannerAdWidget(
                      zoneId: "1530754",
                      adSize: GNAdSize.w300h250,
                      onReceiveAd: (String zoneId) {
                        print("GNBannerAdWidget onReceiveAd flutter: $zoneId");
                      },
                      onFailedToReceiveAd: (String zoneId) {
                        print(
                            "GNBannerAdWidget onFailedToReceiveAd flutter: $zoneId");
                      },
                      onStartExternalBrowser: (String zoneId) {
                        print(
                            "GNBannerAdWidget onStartExternalBrowser: $zoneId");
                      },
                    ),
                  ),
                ),
              ],
            ),
            Column(
              children: [
                Container(
                  margin: const EdgeInsets.all(10),
                  child: const Text(
                    "Banner with mediation",
                    style: TextStyle(
                        fontSize: 28,
                        fontWeight: FontWeight.bold,
                        color: Colors.orange),
                  ),
                ),
                Card(
                  child: SizedBox(
                    width: 320,
                    height: 100,
                    child: GNBannerAdWidget(
                      zoneId: "1530755",
                      adSize: GNAdSize.w320h100,
                      isRTB: true,
                      onReceiveAd: (String zoneId) {
                        print("GNBannerAdWidget onReceiveAd flutter: $zoneId");
                      },
                      onFailedToReceiveAd: (String zoneId) {
                        print(
                            "GNBannerAdWidget onFailedToReceiveAd flutter: $zoneId");
                      },
                    ),
                  ),
                ),
                Container(
                  margin: const EdgeInsets.all(20),
                  child: Column(
                    children: [
                      TextButton(
                          onPressed: () {
                            _loadAd();
                          },
                          child: Text(
                            "Load Interstitial Ad",
                            style: TextStyle(
                                fontSize: 22,
                                color: _isInterstitialAdLoaded
                                    ? Colors.grey
                                    : Colors.blueAccent),
                          )),
                      TextButton(
                          onPressed: () {
                            _showAd();
                          },
                          child: Text("Show Interstitial Ad",
                              style: TextStyle(
                                  fontSize: 22,
                                  color: _isInterstitialAdLoaded
                                      ? Colors.blueAccent
                                      : Colors.grey)))
                    ],
                  ),
                ),
              ],
            ),
          ],
        )),
      ),
    );
  }

  @override
  void onAdClosed() {
    setState(() {
      _isInterstitialAdLoaded = false;
    });
  }

  @override
  void onAdFailedToLoad(int errorCode) {
    print("FullscreenInterstitial onAdFailedToLoad in flutter");
  }

  @override
  void onAdLoaded() {
    print("FullscreenInterstitial onAdLoaded in flutter");
    Fluttertoast.showToast(
        msg: "Interstitial ad is loaded",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.BOTTOM,
        timeInSecForIosWeb: 1,
        backgroundColor: Colors.red,
        textColor: Colors.white,
        fontSize: 16.0);

    setState(() {
      _isInterstitialAdLoaded = true;
    });
  }

  @override
  void onAdOpened() {}
}
0
likes
130
pub points
0%
popularity

Publisher

unverified uploader

Geniee SDK for Flutter platform

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on gns_flutter_plugin