Skip to content

Commit

Permalink
Merge pull request #14 from naaando/46-adiciona-anuncios
Browse files Browse the repository at this point in the history
46 adiciona anuncios
  • Loading branch information
naaando authored Nov 21, 2023
2 parents 139df47 + 4c4101a commit 238ffbb
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pets/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
android:label="pets"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="@string/ads_app_id"/>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
Expand Down
1 change: 1 addition & 0 deletions pets/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<resources>
<string name="facebook_app_id">310440038020217</string>
<string name="facebook_client_token">a93e5f78a3a9bfdd7900c418def3f820</string>
<string name="ads_app_id">ca-app-pub-4189251425238819~3402536887</string>
</resources>
95 changes: 95 additions & 0 deletions pets/lib/components/small_native_ad.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import 'dart:io';

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

class SmallNativeAd extends StatefulWidget {
const SmallNativeAd({super.key});

@override
SmallNativeAdState createState() => SmallNativeAdState();
}

class SmallNativeAdState extends State<SmallNativeAd> {
NativeAd? _nativeAd;
bool _nativeAdIsLoaded = false;
final double _adAspectRatioSmall = (91 / 355);

final String _adUnitId =
Platform.isAndroid ? 'ca-app-pub-4189251425238819/7196697261' : '';

@override
void initState() {
super.initState();

_loadAd();
}

@override
Widget build(BuildContext context) {
return SizedBox(
height: MediaQuery.of(context).size.width * _adAspectRatioSmall,
width: MediaQuery.of(context).size.width,
child: _nativeAdIsLoaded && _nativeAd != null
? AdWidget(ad: _nativeAd!)
: null,
);
}

/// Loads a native ad.
void _loadAd() {
setState(() {
_nativeAdIsLoaded = false;
});

_nativeAd = NativeAd(
adUnitId: _adUnitId,
listener: NativeAdListener(
onAdLoaded: (ad) {
// ignore: avoid_print
print('$NativeAd loaded.');
setState(() {
_nativeAdIsLoaded = true;
});
},
onAdFailedToLoad: (ad, error) {
// ignore: avoid_print
print('$NativeAd failedToLoad: $error');
ad.dispose();
},
onAdClicked: (ad) {},
onAdImpression: (ad) {},
onAdClosed: (ad) {},
onAdOpened: (ad) {},
onAdWillDismissScreen: (ad) {},
onPaidEvent: (ad, valueMicros, precision, currencyCode) {},
),
request: const AdRequest(),
nativeTemplateStyle: NativeTemplateStyle(
templateType: TemplateType.small,
mainBackgroundColor: const Color(0xfffffbed),
callToActionTextStyle: NativeTemplateTextStyle(
textColor: Colors.white,
style: NativeTemplateFontStyle.monospace,
size: 16.0),
primaryTextStyle: NativeTemplateTextStyle(
textColor: Colors.black,
style: NativeTemplateFontStyle.bold,
size: 16.0),
secondaryTextStyle: NativeTemplateTextStyle(
textColor: Colors.black,
style: NativeTemplateFontStyle.italic,
size: 16.0),
tertiaryTextStyle: NativeTemplateTextStyle(
textColor: Colors.black,
style: NativeTemplateFontStyle.normal,
size: 16.0)))
..load();
}

@override
void dispose() {
_nativeAd?.dispose();
super.dispose();
}
}
3 changes: 3 additions & 0 deletions pets/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:sentry_logging/sentry_logging.dart';
import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
import 'package:flutter_timezone/flutter_timezone.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

import 'notifications.dart';

Expand All @@ -27,6 +28,8 @@ Future<void> _configureLocalTimeZone() async {
void main() async {
WidgetsFlutterBinding.ensureInitialized();

MobileAds.instance.initialize();

String locale = Platform.localeName;

initializeDateFormatting(locale);
Expand Down
2 changes: 2 additions & 0 deletions pets/lib/pages/dashboard_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:pets/components/lista_ocorridos.dart';
import 'package:pets/components/lista_pets.dart';
import 'package:pets/components/lista_proximos.dart';
import 'package:pets/components/small_native_ad.dart';
import 'package:pets/provider/pet_provider.dart';

class DashboardTab extends HookConsumerWidget {
Expand Down Expand Up @@ -30,6 +31,7 @@ class DashboardTab extends HookConsumerWidget {
padding: const EdgeInsets.symmetric(vertical: 12),
child: const ListaPets(),
),
const SmallNativeAd(),
Container(
padding: const EdgeInsets.all(12),
child: ListaProximos(showMenu),
Expand Down
48 changes: 48 additions & 0 deletions pets/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.2.1+1"
google_mobile_ads:
dependency: "direct main"
description:
name: google_mobile_ads
sha256: "7b8915f0ad358f49ba7d547b5187204cfe72ca668fb83aa303f96a2eacdc4033"
url: "https://pub.dev"
source: hosted
version: "3.1.0"
google_sign_in:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1306,6 +1314,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
visibility_detector:
dependency: transitive
description:
name: visibility_detector
sha256: dd5cc11e13494f432d15939c3aa8ae76844c42b723398643ce9addb88a5ed420
url: "https://pub.dev"
source: hosted
version: "0.4.0+2"
vm_service:
dependency: transitive
description:
Expand Down Expand Up @@ -1338,6 +1354,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.4.0"
webview_flutter:
dependency: transitive
description:
name: webview_flutter
sha256: "42393b4492e629aa3a88618530a4a00de8bb46e50e7b3993fedbfdc5352f0dbf"
url: "https://pub.dev"
source: hosted
version: "4.4.2"
webview_flutter_android:
dependency: transitive
description:
name: webview_flutter_android
sha256: "8326ee235f87605a2bfc444a4abc897f4abc78d83f054ba7d3d1074ce82b4fbf"
url: "https://pub.dev"
source: hosted
version: "3.12.1"
webview_flutter_platform_interface:
dependency: transitive
description:
name: webview_flutter_platform_interface
sha256: adb8c03c2be231bea5a8ed0e9039e9d18dbb049603376beaefa15393ede468a5
url: "https://pub.dev"
source: hosted
version: "2.7.0"
webview_flutter_wkwebview:
dependency: transitive
description:
name: webview_flutter_wkwebview
sha256: accdaaa49a2aca2dc3c3230907988954cdd23fed0a19525d6c9789d380f4dc76
url: "https://pub.dev"
source: hosted
version: "3.9.4"
win32:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion pets/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.8.3+40
version: 1.8.4+41

environment:
sdk: '>=3.0.0 <4.0.0'
Expand Down Expand Up @@ -63,6 +63,7 @@ dependencies:
sentry_flutter: ^7.10.1
sentry_logging: ^7.10.1
sentry_dio: ^7.10.1
google_mobile_ads: ^3.1.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 238ffbb

Please sign in to comment.