Skip to content

Commit

Permalink
Pokedex with Flutter
Browse files Browse the repository at this point in the history
  • Loading branch information
imayush-chauhan committed Dec 3, 2021
1 parent ee8ea1a commit f59aff2
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 21 deletions.
6 changes: 3 additions & 3 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<application
android:label="pokidexayu"
android:icon="@mipmap/ic_launcher">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3028010056599796~5748304131"/>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
Expand Down Expand Up @@ -38,8 +41,5 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
</application>
</manifest>
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import 'package:pokidexayu/pokemon/pokemon.dart';

void main() async{
WidgetsFlutterBinding.ensureInitialized();
MobileAds.instance.initialize();
await Firebase.initializeApp();
await MobileAds.instance.initialize();
runApp(MyApp());
}

Expand Down
107 changes: 92 additions & 15 deletions lib/pokemon/infoScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ class _InfoScreenState extends State<InfoScreen> {
if(Data.showAds == true){
print("inside banner ads>>>>>>>>>>>>>>>");
_ad = BannerAd(
// adUnitId: "ca-app-pub-3028010056599796/1261198552",
// adUnitId: "ca-app-pub-3028010056599796/1626317951",
adUnitId: BannerAd.testAdUnitId,
// adUnitId: "ca-app-pub-3940256099942544/6300978111",
// adUnitId: "ca-app-pub-3028010056599796/1261198552",
size: AdSize.banner,
request: AdRequest(),
listener: BannerAdListener(
listener: AdListener(
onAdLoaded: (_){
setState(() {
isLoaded = true;
Expand All @@ -57,9 +60,15 @@ class _InfoScreenState extends State<InfoScreen> {
},
onAdFailedToLoad: (_ad,error){
print("Ad failed to load on Error: $error");
_ad.dispose();
}
),
);
Future.delayed(const Duration(milliseconds: 300), () {
setState(() {
_ad!.load();
});
});
}
}

Expand Down Expand Up @@ -90,6 +99,38 @@ class _InfoScreenState extends State<InfoScreen> {
}
}

InterstitialAd? _in;
bool isLoadedIn = false;

loadInAd(){
if(Data.showAds == true){
_in = InterstitialAd(
// adUnitId: "ca-app-pub-3028010056599796/1200794278",
adUnitId: InterstitialAd.testAdUnitId,
request: AdRequest(
keywords: ["amazon", "games", "land", "collage","toys","learn","coding","food"],
),
listener: AdListener(
onAdLoaded: (_){
setState(() {
isLoadedIn = true;
});
},
onAdFailedToLoad: (_ad,error){
print("Ad failed to load on Error: $error");
}
),
);
_in!.load();
}
}

showInAd(){
if(isLoadedIn == true){
_in!.show();
}
}

setFav() async {
SharedPreferences myPrefs = await SharedPreferences.getInstance();
setState(() {
Expand Down Expand Up @@ -262,8 +303,11 @@ class _InfoScreenState extends State<InfoScreen> {
SafeArea(
child: GestureDetector(
onTap: () {
setState(() {
isType = false;
Future.delayed(Duration(milliseconds: 100), () {
setState(() {
isType = false;
click = "";
});
});
},
child: Container(
Expand Down Expand Up @@ -418,12 +462,23 @@ class _InfoScreenState extends State<InfoScreen> {
children: [
GestureDetector(
onTap: () {
setState(() {
isType == false ?
Future.delayed(Duration(milliseconds: 500), () {
setState(() {
click =
Data.poke["pokemon"][widget
.inx]["typeofpokemon"][0];
});
}) : setState(() {
click =
Data.poke["pokemon"][widget
.inx]["typeofpokemon"][0];
isType = true;
});
Future.delayed(Duration(milliseconds: 100), () {
setState(() {
isType = true;
});
});
},
child: Container(
height: 45,
Expand Down Expand Up @@ -455,12 +510,23 @@ class _InfoScreenState extends State<InfoScreen> {
?
GestureDetector(
onTap: () {
setState(() {
click =
Data.poke["pokemon"][widget
.inx]["typeofpokemon"][1];
isType = true;
});
isType == false ?
Future.delayed(Duration(milliseconds: 500), () {
setState(() {
click =
Data.poke["pokemon"][widget
.inx]["typeofpokemon"][1];
});
}) : setState(() {
click =
Data.poke["pokemon"][widget
.inx]["typeofpokemon"][1];
});
Future.delayed(Duration(milliseconds: 100), () {
setState(() {
isType = true;
});
});
},
child: Container(
height: 45,
Expand Down Expand Up @@ -1227,12 +1293,23 @@ class _InfoScreenState extends State<InfoScreen> {
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
setState(() {
isType == false ?
Future.delayed(Duration(milliseconds: 500), () {
setState(() {
click =
Data.poke["pokemon"][widget
.inx]["weaknesses"][index];
});
}) : setState(() {
click =
Data.poke["pokemon"][widget
.inx]["weaknesses"][index];
isType = true;
});
Future.delayed(Duration(milliseconds: 100), () {
setState(() {
isType = true;
});
});
},
child: Container(
decoration: BoxDecoration(
Expand Down Expand Up @@ -1745,8 +1822,8 @@ class _InfoScreenState extends State<InfoScreen> {
),),
],
),
isType == false ?
Text("") :
isType == false || click == "" ?
CircularProgressIndicator() :
typePokemon(context),
],
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ packages:
name: google_mobile_ads
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "0.12.2+1"
http:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies:
cloud_firestore:
firebase_auth:
firebase_storage:
google_mobile_ads:
google_mobile_ads: ^0.12.1+1
cached_network_image: ^3.0.0
url_launcher:
http:
Expand Down

0 comments on commit f59aff2

Please sign in to comment.