google_native_mobile_ads 1.0.2 google_native_mobile_ads: ^1.0.2 copied to clipboard
This package helps in displaying native ads , it supports creating full screen and inline native ads with very minimal code required from android side.
import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'full_screen_ad.dart';
import 'inline_ad.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await MobileAds.instance.initialize();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.indigo,
),
home: const MainScreen(),
);
}
}
class MainScreen extends StatefulWidget {
const MainScreen({Key? key}) : super(key: key);
@override
State<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Main screen'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
child: const Text('Show inline native ad'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const MediumSizeNativeAdScreen(),
),
);
},
),
ElevatedButton(
child: const Text('Show Full screen native ad'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const FullScreenNativeAdScreen(),
),
);
},
),
],
),
),
);
}
}