notix_ads 0.0.3 notix_ads: ^0.0.3 copied to clipboard
Effortlessly manage Banner and AppOpen Ads on Android Notix integration..
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:notix_ads/notix_ads.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
Widget? _banner;
final _notixAdsPlugin = NotixAds();
@override
void initState() {
super.initState();
WidgetsBinding.instance?.addObserver(this);
initPlatformState();
}
@override
void dispose() {
WidgetsBinding.instance?.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.paused) {
NotixAds().appOpen(/*You Zone ID*/);
}
}
Future<void> initPlatformState() async {
try {
_banner = await _notixAdsPlugin.loadBanner(/*You Zone ID*/);
} on PlatformException {
_banner = const Text('Failed to get platform version.');
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Notix_Ads'),
),
body: Center(
child: _banner,
),
),
);
}
}