Skip to content

Commit

Permalink
ptch: improve and add ads
Browse files Browse the repository at this point in the history
  • Loading branch information
bharat-1809 committed Mar 25, 2021
1 parent 51c3b0a commit 943c26c
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 124 deletions.
62 changes: 57 additions & 5 deletions lib/component/appAds.dart
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
import 'dart:io';

import 'package:google_mobile_ads/google_mobile_ads.dart';

class AddManager {
static String get appId {
AddManager(this.initialization);
Future<InitializationStatus> initialization;

String get appId {
if (Platform.isAndroid) {
return "ca-app-pub-1828204131712236~3033530989";//"ca-app-pub-3940256099942544~4354546703";
return "ca-app-pub-1828204131712236~3033530989";
} else if (Platform.isIOS) {
return "APPSTORE_KEY";
} else {
throw UnsupportedError("Unsupported Platform");
}
}

static String get bannerAdUnitId {
String get bottomBannerAdId {
if (Platform.isAndroid) {
return "ca-app-pub-1828204131712236/2650387606";//"ca-app-pub-3940256099942544/8865242552";
return "ca-app-pub-1828204131712236/2650387606";
} else if (Platform.isIOS) {
return "IOS_BANNER_KEY";
} else {
throw UnsupportedError("Unsupported Platform");
}
}

static String get interstitialAdUnitId {
String get topBannerAdId {
if (Platform.isAndroid) {
return "ca-app-pub-1828204131712236/8522925412";
} else if (Platform.isIOS) {
return "IOS_BANNER_KEY";
} else {
throw UnsupportedError("Unsupported Platform");
}
}

String get themeInterstitialAdId {
if (Platform.isAndroid) {
return "ca-app-pub-1828204131712236/8318238523";
} else if (Platform.isIOS) {
Expand All @@ -30,4 +45,41 @@ class AddManager {
throw new UnsupportedError("Unsupported platform");
}
}

String get aboutInterstitialAdId {
if (Platform.isAndroid) {
return "ca-app-pub-1828204131712236/1957517061";
} else if (Platform.isIOS) {
return "IOS_INTERSTITIAL_AD_ID";
} else {
throw new UnsupportedError("Unsupported platform");
}
}

String get testBanerAdId => 'ca-app-pub-3940256099942544/6300978111';
String get testInterstitialAdId => 'ca-app-pub-3940256099942544/1033173712';

AdListener get adListener => _adListener;

final AdListener _adListener = AdListener(
// Called when an ad is successfully received.
onAdLoaded: (Ad ad) => print('Ad--${ad.adUnitId} loaded.'),
// Called when an ad request failed.
onAdFailedToLoad: (Ad ad, LoadAdError error) {
ad.dispose();
print('Ad--${ad.adUnitId} failed to load: $error');
},
// Called when an ad opens an overlay that covers the screen.
onAdOpened: (Ad ad) => print('Ad--${ad.adUnitId} opened.'),
// Called when an ad removes an overlay that covers the screen.
onAdClosed: (Ad ad) {
print('Ad--${ad.adUnitId} closed.');
if (ad is InterstitialAd) {
ad.dispose();
ad.load();
}
},
// Called when an ad is in the process of leaving the application.
onApplicationExit: (Ad ad) => print('Ad--${ad.adUnitId} ---- Left application.'),
);
}
18 changes: 9 additions & 9 deletions lib/component/category_tile.dart
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:page_transition/page_transition.dart';
import 'package:unito/component/category.dart';
import 'package:unito/screens/unit_screen.dart';

Expand All @@ -19,10 +18,11 @@ class CategoryTile extends StatelessWidget {
final height = MediaQuery.of(context).size.height;

void _openConverterRoute(Category categoryUnit) {
Navigator.of(context).push(PageTransition(
child: UnitConverter(category: categoryUnit),
type: PageTransitionType.rightToLeftWithFade,
));
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => UnitConverter(category: categoryUnit),
),
);
}

return Padding(
Expand All @@ -35,7 +35,7 @@ class CategoryTile extends StatelessWidget {
borderRadius: _borderRadius,
boxShadow: [
BoxShadow(
color: Color.fromRGBO(46, 46, 46, 0.05),
color: Color.fromRGBO(46, 46, 46, 0.03),
offset: Offset(0.0, 0.0),
spreadRadius: 5,
blurRadius: 10,
Expand All @@ -61,11 +61,11 @@ class CategoryTile extends StatelessWidget {
padding: _padding8,
child: Image.asset(
category.iconLocation,
height: 0.07226810673443456392 * height,
width: 0.07226810673443456392 * height,
height: 0.065 * height,
width: 0.065 * height,
),
),
SizedBox(height: 0.00222363405336721735 * height),
SizedBox(height: 0.0022 * height),
Text(
category.name,
style: Theme.of(context).textTheme.caption,
Expand Down
17 changes: 12 additions & 5 deletions lib/main.dart
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:provider/provider.dart';
import 'package:unito/app.dart';
import 'package:unito/component/appAds.dart';
import 'package:unito/theme/themeChanger.dart';

void main() {
/// This ensures that the orientation is always portrait
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]).then((_) => runApp(
Unito(),
));
final initFuture = MobileAds.instance.initialize();
final adManager = AddManager(initFuture);

/// This ensures that the orientation is always portrait
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]).then(
(_) => runApp(Provider.value(
value: adManager,
builder: (context, child) => Unito(),
)),
);
}

/// Unit Converter App.
Expand Down
Loading

0 comments on commit 943c26c

Please sign in to comment.