ak_ads_plugin 0.1.1
ak_ads_plugin: ^0.1.1 copied to clipboard
Ads plugin for Android only
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:ak_ads_plugin/ak_ads_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> {
String _platformVersion = 'Unknown';
final _akAdsPlugin = AkAdsPlugin();
bool apiCallDone = false;
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
String platformVersion;
try {
platformVersion = await _akAdsPlugin.getApiResponse(arguments: {"ad_show": true}) ?? 'Unknown platform version';
apiCallDone = true;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
var scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
key: scaffoldKey,
drawer: Drawer(),
drawerEnableOpenDragGesture: false,
appBar: AppBar(
title: const Text('Plugin example app'),
leading: Builder(
builder: (context) => // Ensure Scaffold is in context
IconButton(icon: Icon(Icons.menu), onPressed: () => Scaffold.of(context).openDrawer()),
),
),
backgroundColor: Colors.red,
body: SizedBox(
height: MediaQuery.of(context).size.height,
child: SingleChildScrollView(
child: apiCallDone
? Column(
children: [
BannerAdView(),
NativeAdView(
adSize: "small",
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: NativeAdView(
adSize: "medium",
),
),
NativeAdView(
adSize: "big",
),
QuizAdView(),
MaterialButton(
onPressed: () {
_akAdsPlugin.callInterstitialAds();
},
child: Text("Inter Click"),
color: Colors.blueGrey,
)
],
)
: Container(),
),
),
floatingActionButton: FloatingActionButton(onPressed: () {
scaffoldKey.currentState?.openDrawer();
}),
),
);
}
}