vmax_flutter 1.0.2 copy "vmax_flutter: ^1.0.2" to clipboard
vmax_flutter: ^1.0.2 copied to clipboard

outdated

VmaxFlutter SDK allows the publishers to display wide variety of ads.

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  // You will get the below values from Vmax dashboard.
  int accountId = 0;
  int appId = 0;
  String secretKey = '';
  String tagId = '';

  VmaxFlutterAdSpace? _bannerAd1;

  bool isManagerLoaded = false;
  bool isAdReady = false;

  @override
  void initState() {
    super.initState();
    if (accountId <= 0 || appId <= 0 || secretKey.isEmpty) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary("AccountId, AppId & SecretKey can't be empty.")
      ]);
    } else {
      _loadVmaxManager();
    }
  }

  @override
  void dispose() {
    super.dispose();
    _bannerAd1?.closeAd();
    _bannerAd1 = null;
  }

  void _loadVmaxManager() async {
    VmaxFlutterManager.instance.initialize(accountId: accountId, appId: appId, secretKey: secretKey, listener: InitializationStatusListener(
        onSuccess: (){
          isManagerLoaded = true;
          print("VmaxManager Initialization Success");
        },
        onFailure: (){
          print("VmaxManager Initialization Failed");
        })
    );
  }

  void _loadAd() async {
    _bannerAd1 = VmaxFlutterAdSpace(tagId: tagId, listener: VmaxFlutterAdSpaceListener(
      onAdReady: () {
        isAdReady = true;
        print("VmaxFlutterAdSpace onAdReady");
      },
      onAdRender: (){
        print("VmaxFlutterAdSpace onAdRender");
      },
      onAdRefresh: () {
        print("VmaxFlutterAdSpace onAdRefresh");
      },
      onAdError: () {
        print("VmaxFlutterAdSpace onAdError");
      },
      onAdClick: (){
        print("VmaxFlutterAdSpace onAdClick");
      },)
    );
    _bannerAd1?.cacheAd();
  }

  void _showAd() async {
    if (isManagerLoaded && isAdReady) {
      setState(() {});
    } else {
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary("VmaxFlutterAdSpace failed to load the ad.")
      ]);
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Vmax Example App'),
        ),
        body: Center(
          child: Column(
            // crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(onPressed: _loadAd, child: const Text("Cache Ad")),
              ElevatedButton(onPressed: _showAd, child: const Text("Show Ad")),
              const SizedBox(height: 10),
              if (isManagerLoaded && isAdReady)
                VmaxWidget(adSpace: _bannerAd1!)
              else
                const SizedBox(
                  width: 320,
                  height: 50,
                  child: Placeholder(),
                )
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
0
points
17
downloads

Publisher

verified publishervmax.com

Weekly Downloads

VmaxFlutter SDK allows the publishers to display wide variety of ads.

Homepage

License

unknown (license)

Dependencies

flutter, google_mobile_ads, webview_flutter

More

Packages that depend on vmax_flutter

Packages that implement vmax_flutter