Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ad inspector button to mediation example #1132

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -498,6 +499,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -516,6 +518,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
13 changes: 13 additions & 0 deletions samples/admob/mediation_example/lib/app_bar_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// Example app bar class.
class AppBarItem {
/// Helper variable for the ad inspector button text.
static const adInpsectorText = 'Ad Inspector';

/// Button text.
final String label;
/// Button value.
final int value;

/// Initialize the class.
AppBarItem(this.label, this.value);
}
75 changes: 25 additions & 50 deletions samples/admob/mediation_example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:mediationexample/my_method_channel.dart';

import 'app_bar_item.dart';
import 'my_method_channel.dart';

void main() {
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -30,23 +32,14 @@ void main() {
runApp(MyApp());
}

/// A simple app that loads an ad and shows a button which increments a counter.
/// An example app that loads an ad and shows a button which increments a counter.
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Mediation Example',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
Expand All @@ -57,15 +50,6 @@ class MyApp extends StatelessWidget {
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
Expand All @@ -80,11 +64,6 @@ class _MyHomePageState extends State<MyHomePage> {

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
Expand Down Expand Up @@ -117,38 +96,34 @@ class _MyHomePageState extends State<MyHomePage> {
)..load();
}

List<Widget> _appBarActions() {
final adInspectorMenuItem = AppBarItem(AppBarItem.adInpsectorText, 0);

return <Widget>[
PopupMenuButton<AppBarItem>(
itemBuilder: (BuildContext context) => <PopupMenuEntry<AppBarItem>>[
PopupMenuItem<AppBarItem>(
value: adInspectorMenuItem,
child: Text(adInspectorMenuItem.label),
),
],
onSelected: (item) {
MobileAds.instance.openAdInspector((error) {
// Error will be non-null if ad inspector closed due to an error.
});
})
];
}

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
actions: _appBarActions(),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
Expand All @@ -172,7 +147,7 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
),
);
}
}
2 changes: 1 addition & 1 deletion samples/admob/mediation_example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: '>=3.2.0 <4.0.0'

dependencies:
flutter:
Expand Down
30 changes: 0 additions & 30 deletions samples/admob/mediation_example/test/widget_test.dart

This file was deleted.

Binary file removed samples/admob/mediation_example/web/favicon.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
98 changes: 0 additions & 98 deletions samples/admob/mediation_example/web/index.html

This file was deleted.

23 changes: 0 additions & 23 deletions samples/admob/mediation_example/web/manifest.json

This file was deleted.