From 304d2682d066ee61851853b6552d2725533ac6f0 Mon Sep 17 00:00:00 2001 From: Fernando da Silva Sousa Date: Mon, 20 Nov 2023 20:21:31 -0300 Subject: [PATCH 1/3] Adiciona metadados de anuncios --- pets/android/app/src/main/AndroidManifest.xml | 3 +++ pets/android/app/src/main/res/values/strings.xml | 1 + 2 files changed, 4 insertions(+) diff --git a/pets/android/app/src/main/AndroidManifest.xml b/pets/android/app/src/main/AndroidManifest.xml index 56de4c0..d6fcd89 100644 --- a/pets/android/app/src/main/AndroidManifest.xml +++ b/pets/android/app/src/main/AndroidManifest.xml @@ -8,6 +8,9 @@ android:label="pets" android:name="${applicationName}" android:icon="@mipmap/ic_launcher"> + diff --git a/pets/android/app/src/main/res/values/strings.xml b/pets/android/app/src/main/res/values/strings.xml index f2630bc..808131c 100644 --- a/pets/android/app/src/main/res/values/strings.xml +++ b/pets/android/app/src/main/res/values/strings.xml @@ -2,4 +2,5 @@ 310440038020217 a93e5f78a3a9bfdd7900c418def3f820 + ca-app-pub-4189251425238819~3402536887 \ No newline at end of file From 2b8d8385494c4bf4fef96f19162d3fb673a33bbd Mon Sep 17 00:00:00 2001 From: Fernando da Silva Sousa Date: Mon, 20 Nov 2023 20:50:29 -0300 Subject: [PATCH 2/3] Adiciona sdk de anuncios e widget de anuncio --- pets/lib/components/small_native_ad.dart | 95 ++++++++++++++++++++++++ pets/lib/main.dart | 3 + pets/lib/pages/dashboard_tab.dart | 2 + pets/pubspec.lock | 48 ++++++++++++ pets/pubspec.yaml | 1 + 5 files changed, 149 insertions(+) create mode 100644 pets/lib/components/small_native_ad.dart diff --git a/pets/lib/components/small_native_ad.dart b/pets/lib/components/small_native_ad.dart new file mode 100644 index 0000000..9aa5538 --- /dev/null +++ b/pets/lib/components/small_native_ad.dart @@ -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 { + 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(); + } +} diff --git a/pets/lib/main.dart b/pets/lib/main.dart index b2fcd83..f1ffc8b 100644 --- a/pets/lib/main.dart +++ b/pets/lib/main.dart @@ -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'; @@ -27,6 +28,8 @@ Future _configureLocalTimeZone() async { void main() async { WidgetsFlutterBinding.ensureInitialized(); + MobileAds.instance.initialize(); + String locale = Platform.localeName; initializeDateFormatting(locale); diff --git a/pets/lib/pages/dashboard_tab.dart b/pets/lib/pages/dashboard_tab.dart index 2d4447d..a1b4226 100644 --- a/pets/lib/pages/dashboard_tab.dart +++ b/pets/lib/pages/dashboard_tab.dart @@ -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 { @@ -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), diff --git a/pets/pubspec.lock b/pets/pubspec.lock index c85e9e6..4efec2b 100644 --- a/pets/pubspec.lock +++ b/pets/pubspec.lock @@ -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: @@ -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: @@ -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: diff --git a/pets/pubspec.yaml b/pets/pubspec.yaml index df5e1a9..eeda9d4 100644 --- a/pets/pubspec.yaml +++ b/pets/pubspec.yaml @@ -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: From 4c4101a2634186e542c44870d6bd35f336b49e68 Mon Sep 17 00:00:00 2001 From: Fernando da Silva Sousa Date: Mon, 20 Nov 2023 21:03:58 -0300 Subject: [PATCH 3/3] v1.8.4 --- pets/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pets/pubspec.yaml b/pets/pubspec.yaml index eeda9d4..0154c6f 100644 --- a/pets/pubspec.yaml +++ b/pets/pubspec.yaml @@ -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'