Anuncios do Admob no Flutter

pubspec.yaml

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
firebase_admob: ^0.9.0+9

AndroidManifest.xml

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="[ADMOB_APP_ID]"/>

Main

import 'package:firebase_admob/firebase_admob.dart';
 @override
Widget (BuildContext context) {
  FirebaseAdMob.instance.initialize(appId: "[ADMOB_APP_ID]");
  myBanner
..load()
..show(
anchorOffset: 60.0,
horizontalCenterOffset: 10.0,
anchorType: AnchorType.bottom,
);


myInterstitial
..load()
..show(
anchorType: AnchorType.bottom,
anchorOffset: 0.0,
horizontalCenterOffset: 0.0,
);

return Scaffold(

 
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: <String>['games', 'game','Kids'],
contentUrl: 'https://flutter.io',
childDirected: false,
testDevices: <String>[], // Android emulators are considered test devices
);

BannerAd myBanner = BannerAd(
adUnitId: [Your Banner.Ad.Id],
size: AdSize.smartBanner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("BannerAd event is $event");
},
);

InterstitialAd myInterstitial = InterstitialAd(
adUnitId: [Your Interstitial.Ad_Id],
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("InterstitialAd event is $event");
},
);

 

JunKenPon – Como eu fiz este aplicativo em Flutter (#2 Gesture Detector)

#1 - Criação do Interface

import 'package:flutter/material.dart';
import 'package:jankenpon/Game.dart';

void main(){
runApp(MaterialApp(
home: Game(),
debugShowCheckedModeBanner: false,
));
}
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Game extends StatefulWidget {
@override
_GameState createState() => _GameState();
}

class _GameState extends State<Game> {

var _imageAppChoice=AssetImage("images/base.png");
var _batleResult="Batle Field";
var _resultado="";
var _userVictory=0, _appVictory=0;

var _imageBatleResult=AssetImage("images/base.png");

void _selectOption(String userChoice) {
var options = ["rock", "paper", "scissors", "lizard", "spock"];
var number = Random().nextInt(5);
var appChoice = options[number];

//Show App Choice Image
switch (appChoice) {
case "rock":
setState(() {
this._imageAppChoice = AssetImage("images/rock.png");
});
break;
case "paper":
setState(() {
this._imageAppChoice = AssetImage("images/paper.png");
});
break;
case "scissors":
setState(() {
this._imageAppChoice = AssetImage("images/scissors.png");
});
break;
case "lizard":
setState(() {
this._imageAppChoice = AssetImage("images/lizard.png");
});
break;
case "spock":
setState(() {
this._imageAppChoice = AssetImage("images/spock.png");
});
break;
}

//If User Wins: Change Imagem
if(userChoice=="rock" && appChoice == "scissors") {
this._imageBatleResult=AssetImage("images/rock_scissors_win.png");
_batleResult="You Win! Your rock crushed the scissors";
}
if(userChoice=="rock" && appChoice == "lizard") {
this._imageBatleResult=AssetImage("images/rock_lizard_win.png");
_batleResult="You Win! Your rock smashed the lizard";
}
if(userChoice=="lizard" && appChoice == "paper") {
this._imageBatleResult=AssetImage("images/lizard_paper_win.png");
_batleResult="You Win! Your lizard ate the paper";
}
if(userChoice=="lizard" && appChoice == "spock") {
this._imageBatleResult=AssetImage("images/lizard_spock_win.png");
_batleResult="You Win! Your lizard poisoned the Spock";
}
if(userChoice=="spock" && appChoice == "scissors") {
this._imageBatleResult=AssetImage("images/spock_scissors_win.png");
_batleResult="You Win! Your Spock destroyed the scissors";
}
if(userChoice=="spock" && appChoice == "rock") {
this._imageBatleResult=AssetImage("images/spock_rock_win.png");
_batleResult="You Win! Your Spock vaporized the rock";
}
if(userChoice=="scissors" && appChoice == "paper") {
this._imageBatleResult=AssetImage("images/scissors_paper_win.png");
_batleResult="You Win! Your scissors cut the paper";
}
if(userChoice=="scissors" && appChoice == "lizard") {
this._imageBatleResult=AssetImage("images/scissors_lizard_win.png");
_batleResult="You Win! Your scissors beheaded the lizard";
}
if(userChoice=="paper" && appChoice == "rock") {
this._imageBatleResult=AssetImage("images/paper_rock_win.png");
_batleResult="You Win! Your paper covered the rock";
}
if(userChoice=="paper" && appChoice == "spock") {
this._imageBatleResult=AssetImage("images/paper_spock_win.png");
_batleResult="You Win! Your paper disapproves Spock";
}

//Image when user lose
if(appChoice=="rock" && userChoice == "scissors") {
this._imageBatleResult=AssetImage("images/rock_scissors_lose.png");
_batleResult="You Lose! Your scissors were destroyed by the rock";
}
if(appChoice=="rock" && userChoice == "lizard") {
this._imageBatleResult=AssetImage("images/rock_lizard_lose.png");
_batleResult="You Lose! Your lizard was smashed by the rock";
}
if(appChoice=="lizard" && userChoice == "paper") {
this._imageBatleResult=AssetImage("images/lizard_paper_lose.png");
_batleResult="You Lose! Your paper was eaten by the lizard";
}
if(appChoice=="lizard" && userChoice == "spock") {
this._imageBatleResult=AssetImage("images/lizard_spock_lose.png");
_batleResult="You Lose! Your Spock was poisoned by the lizard";
}
if(appChoice=="spock" && userChoice == "scissors") {
this._imageBatleResult=AssetImage("images/spock_scissors_lose.png");
_batleResult="You Lose! Your scissors were destroyed by Spock";
}

if(appChoice=="spock" && userChoice == "rock") {
this._imageBatleResult=AssetImage("images/spock_rock_lose.png");
_batleResult="You Lose! Your rock was vaporized by Spock";
}
if(appChoice=="scissors" && userChoice == "paper") {
this._imageBatleResult=AssetImage("images/scissors_paper_lose.png");
_batleResult="You Lose! Your paper was cut by scissors";
}
if(appChoice=="scissors" && userChoice == "lizard") {
this._imageBatleResult=AssetImage("images/scissors_lizard_lose.png");
_batleResult="You Lose! Your lizard was beheaded by scissors";
}
if(appChoice=="paper" && userChoice == "rock") {
this._imageBatleResult=AssetImage("images/paper_rock_lose.png");
_batleResult="You Lose! Your rock was covered by the paper";
}
if(appChoice=="paper" && userChoice == "spock") {
this._imageBatleResult=AssetImage("images/paper_spock_lose.png");
_batleResult="You Lose! Your Spock was disapproved by the paper";
}


//Check if user wins
if (
(userChoice == "rock" && appChoice == "scissors") ||
(userChoice == "rock" && appChoice == "lizard") ||
(userChoice == "lizard" && appChoice == "paper") ||
(userChoice == "lizard" && appChoice == "spock") ||
(userChoice == "spock" && appChoice == "scissors") ||
(userChoice == "spock" && appChoice == "rock") ||
(userChoice == "scissors" && appChoice == "paper") ||
(userChoice == "scissors" && appChoice == "lizard") ||
(userChoice == "paper" && appChoice == "rock") ||
(userChoice == "paper" && appChoice == "spock")
) {
setState(() {
_userVictory=_userVictory+1;
_resultado="win";
});

//Check if App wins
} else if (
(appChoice == "rock" && userChoice == "scissors") ||
(appChoice == "rock" && userChoice == "lizard") ||
(appChoice == "lizard" && userChoice == "paper") ||
(appChoice == "lizard" && userChoice == "spock") ||
(appChoice == "spock" && userChoice == "scissors") ||
(appChoice == "spock" && userChoice == "rock") ||
(appChoice == "scissors" && userChoice == "paper") ||
(appChoice == "scissors" && userChoice == "lizard") ||
(appChoice == "paper" && userChoice == "rock") ||
(appChoice == "paper" && userChoice == "spock")
) {
setState(() {
_appVictory=_appVictory+1;
_resultado="lose";

});

//Else - Draw!
} else {
setState(() {
_batleResult = "Draw! You chose the same as the App!";
this._imageBatleResult=AssetImage("images/draw.png");
_resultado="draw";
});
}
}

@override
Widget build(BuildContext context) {

return Scaffold(
appBar: AppBar(
title: Text("JanKenPon")
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 6, bottom: 4),
child: Text(
"App choice",
textAlign: TextAlign.right,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold
),
),
),
Image(image: this._imageAppChoice, height: 60,),
Padding(
padding: EdgeInsets.only(top: 6, bottom: 6, left: 6, right: 6),
child: Text(
this._batleResult,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14,
fontWeight: _resultado=="win"? FontWeight.bold : FontWeight.normal ,
color: _resultado=="win"? Colors.green : _resultado=="lose"? Colors.deepOrange : Colors.black,
),
),
),
Image(image: this._imageBatleResult, height: 90,),
Padding(
padding: EdgeInsets.only(top: 6, bottom: 4),
child: Text(
"Choose your option",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
onTap: ()=>_selectOption("rock"),
child: Image.asset("images/rock.png", height: 80,),

),
GestureDetector(
onTap: ()=>_selectOption("paper"),
child: Image.asset("images/paper.png", height: 70,),
),
GestureDetector(
onTap: ()=>_selectOption("scissors"),
child: Image.asset("images/scissors.png", height: 70,),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
onTap: ()=>_selectOption("lizard"),
child: Image.asset("images/lizard.png", height: 70,),
),
GestureDetector(
onTap: ()=>_selectOption("spock"),
child: Image.asset("images/spock.png", height: 70,),
),
],
),
Padding(
padding: EdgeInsets.only(top: 12, bottom: 0),
child: Text(
"You: $_userVictory | App: $_appVictory",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
fontWeight: _userVictory>_appVictory ? FontWeight.bold : FontWeight.normal ,
color: _userVictory>_appVictory ? Colors.green : _appVictory>_userVictory ? Colors.deepOrange : Colors.black,
),
),
),
]),
);
}
}

 leo.name: jankenpon

description: A new Flutter application.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
sdk: ">=2.1.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2


dev_dependencies:
flutter_test:
sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

assets:
- images/base.png
- images/lizard.png
- images/lizard_paper_lose.png
- images/lizard_paper_win.png
- images/lizard_spock_lose.png
- images/lizard_spock_win.png
- images/logo.png
- images/paper.png
- images/paper_rock_lose.png
- images/paper_rock_win.png
- images/paper_spock_lose.png
- images/paper_spock_win.png
- images/rock.png
- images/rock_lizard_lose.png
- images/rock_lizard_win.png
- images/rock_scissors_lose.png
- images/rock_scissors_win.png
- images/scissors.png
- images/scissors_lizard_lose.png
- images/scissors_lizard_win.png
- images/scissors_paper_lose.png
- images/scissors_paper_win.png
- images/spock.png
- images/spock_rock_lose.png
- images/spock_rock_win.png
- images/spock_scissors_lose.png
- images/spock_scissors_win.png
- images/draw.png

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.

# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages

JunKenPon – Como eu fiz este aplicativo em Flutter

#1 - Criação do Interface

import 'package:flutter/material.dart';
import 'package:jankenpon/Game.dart';

void main(){
runApp(MaterialApp(
home: Game(),
debugShowCheckedModeBanner: false,
));
}
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Game extends StatefulWidget {
@override
_GameState createState() => _GameState();
}

class _GameState extends State<Game> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("JanKenPon")
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 24, bottom: 8),
child: Text(
"App choice",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold
),
),
),
Image.asset("images/base.png", height: 80,),
Padding(
padding: EdgeInsets.only(top: 24, bottom: 8),
child: Text(
"Batle field",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold
),
),
),
Image.asset("images/base.png", height: 120,),
Padding(
padding: EdgeInsets.only(top: 24, bottom: 8),
child: Text(
"Choose your option",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset("images/rock.png", height: 80,),
Image.asset("images/paper.png", height: 80,),
Image.asset("images/scissors.png", height: 80,),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset("images/lizard.png", height: 80,),
Image.asset("images/spock.png", height: 80,),
],
),
Padding(
padding: EdgeInsets.only(top: 24, bottom: 8),
child: Text(
"- Points -",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.normal,
),
),
),
]),
);
}
}