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

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.
  String accountKey = '';
  String appId = '';
  String privateKey = '';
  String keyId = '';
  String tagId = '';

  VmaxFlutterAdSpace? _bannerAd1;

  bool isManagerLoaded = false;
  bool isAdReady = false;

  @override
  void initState() {
    super.initState();
    if (accountKey.isEmpty || appId.isEmpty || privateKey.isEmpty || keyId.isEmpty) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary("AccountKey, AppId, PrivateKey and KeyId can't be empty.")
      ]);
    } else {
      _loadVmaxManager();
    }
  }

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

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

  void _loadAd() async {
    _bannerAd1 = VmaxFlutterAdSpace(tagId: tagId, refreshRate: 30, 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
130
points
17
downloads

Publisher

verified publishervmax.com

Weekly Downloads

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

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter, google_mobile_ads

More

Packages that depend on vmax_flutter

Packages that implement vmax_flutter