sanjagh_flutter 0.0.3 sanjagh_flutter: ^0.0.3 copied to clipboard
Sanjagh plugin for Flutter Applications. Sanjagh is an Advertising Network That helps you monetize your app using Advanced methods. at this time we only support ads on Android Os.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:sanjagh_flutter/sanjagh_flutter.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
SanjaghFlutterPlugin.instance.initialize("1Y8wWn6hqmhQMP0iTVvfhn1A0IU3sIog", market: SanjaghFlutterPlugin.MARKET_GOOGLE_PLAY, primaryColor: "#c44d47", userIdentifier: "Hossein");
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion = "5";
// Platform messages may fail, so we use a try/catch PlatformException.
// try {
// platformVersion = await SanjaghFlutterSdk.platformVersion;
// } on PlatformException {
// platformVersion = 'Failed to get platform version.';
// }
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
InterstitialAd _interstitialAd;
BannerAd _bannerAd;
@override
Widget build(BuildContext context) {
BannerAd bannerAd = BannerAd(
adUnitId: "5mytHpN4fBGHsNoo",
adListener: (AdEvent adEvent, int errorCode) {
},
expandable: null,
entranceType: SanjaghFlutterPlugin.EXPANDABLE_AD_OPTIONS_ENTRANCE_TYPE_NONE,
);
bannerAd.load();
// NativeExpressAd nativeExpressAd = NativeExpressAd(
// adUnitId: "AD_UNIT_ID",
// adListener: (AdEvent adEvent) {
// print(adEvent.toString());
// },
// );
_interstitialAd = InterstitialAd(
adUnitId: "en5vaPDX2PFfsfKS",
adListener: (AdEvent event, int errorCode) {
if (event == AdEvent.loaded) {
_interstitialAd.show();
}
},
);
// bannerAd.show();
// bannerAd.load();
// nativeExpressAd.load();
_interstitialAd.load();
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: getListView(),
// body: Center(
// child: Column(
// children: <Widget>[
// SizedBox(
// width: 400,
// height: 200,
// child: BannerAdView(
// adUnitId: "5mytHpN4fBGHsNoo",
// adListener: (AdEvent event) {
// print(event);
// },
// ),
// ),
// SizedBox(
// width: 400,
// height: 200,
// child: BannerAdView(
// adUnitId: "n6kPN0Ymsz8QeUR4",
// adListener: (AdEvent event) {
// print(event);
// },
// ),
// ),
// RaisedButton(
// child: Text('load'),
// onPressed: () {
// bannerAd.load();
// },
// ),
// ],
// ),
// ),
),
);
}
}
List<String> getListElements() {
var items = List<String>.generate(100, (counter) => "Item $counter");
return items;
}
Widget getListView() {
var listItems = getListElements();
var listView = ListView.builder(itemBuilder: (context, index) {
if (index % 10 == 9) {
return SizedBox(
width: 100,
height: 60,
child: BannerAdView(
adUnitId: "5mytHpN4fBGHsNoo",
adListener: (AdEvent event, int errorCode){
print("$event:$errorCode");
},
),
);
}
return ListTile(
leading: Icon(Icons.arrow_right),
title: Text(listItems[index]),
onTap: () {
debugPrint('${listItems[index]} was tapped');
},
);
});
return listView;
}