vmax_flutter 0.0.1
vmax_flutter: ^0.0.1 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 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();
}
}
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(),
)
],
),
),
),
);
}
}