diff --git a/covas_mobile/android/app/src/main/AndroidManifest.xml b/covas_mobile/android/app/src/main/AndroidManifest.xml index 71290e3..510d7ba 100644 --- a/covas_mobile/android/app/src/main/AndroidManifest.xml +++ b/covas_mobile/android/app/src/main/AndroidManifest.xml @@ -6,6 +6,9 @@ android:label="covas_mobile" android:name="${applicationName}" android:icon="@mipmap/ic_launcher"> + NSLocationWhenInUseUsageDescription Your location is needed for showing nearby events + GADApplicationIdentifier + ca-app-pub-4855855675386260~3438207239 + diff --git a/covas_mobile/lib/classes/ad_helper.dart b/covas_mobile/lib/classes/ad_helper.dart new file mode 100644 index 0000000..92ac812 --- /dev/null +++ b/covas_mobile/lib/classes/ad_helper.dart @@ -0,0 +1,38 @@ +import 'package:google_mobile_ads/google_mobile_ads.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; + +class AdHelper { + static BannerAd? bannerAd; + static bool isBannerAdLoaded = false; + + static Future loadBannerAd(Function setStateCallback) async { + await dotenv.load(fileName: ".env"); + final adUnitId = dotenv.env['AD_UNIT_ID'] ?? ''; + + bannerAd = BannerAd( + adUnitId: adUnitId, // Replace with actual ID + size: AdSize.banner, + request: AdRequest(), + listener: BannerAdListener( + onAdLoaded: (ad) { + setStateCallback(() { + isBannerAdLoaded = true; + }); + }, + onAdFailedToLoad: (ad, error) { + print('Banner Ad failed to load: $error'); + isBannerAdLoaded = false; + ad.dispose(); + }, + ), + ); + + bannerAd?.load(); + } + + static void disposeAd() { + bannerAd?.dispose(); + bannerAd = null; + isBannerAdLoaded = false; + } +} diff --git a/covas_mobile/lib/main.dart b/covas_mobile/lib/main.dart index 25fc343..87b78d0 100644 --- a/covas_mobile/lib/main.dart +++ b/covas_mobile/lib/main.dart @@ -1,8 +1,11 @@ import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:http/http.dart' as http; - +import 'classes/ad_helper.dart'; import 'dart:convert'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:google_mobile_ads/google_mobile_ads.dart'; + import 'dart:io'; //import 'MyHomePage.dart'; @@ -14,7 +17,9 @@ import 'classes/alert.dart'; import 'variable/globals.dart' as globals; import 'package:permission_handler/permission_handler.dart'; -void main() { +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + await MobileAds.instance.initialize(); runApp(MyApp()); } @@ -128,9 +133,17 @@ class _LoginDemoState extends State with ShowAlertDialog { @override void initState() { + super.initState(); + AdHelper.loadBannerAd(setState); + _checkLocationPermission(); start(); - super.initState(); + } + + @override + void dispose() { + AdHelper.disposeAd(); // Dispose of ad when the widget is removed + super.dispose(); } Future _checkLocationPermission() async { @@ -252,7 +265,13 @@ class _LoginDemoState extends State with ShowAlertDialog { onTap: () { Navigator.push( context, MaterialPageRoute(builder: (_) => AddProfile())); - }) + }), + if (AdHelper.isBannerAdLoaded) + SizedBox( + height: AdHelper.bannerAd!.size.height.toDouble(), + width: AdHelper.bannerAd!.size.width.toDouble(), + child: AdWidget(ad: AdHelper.bannerAd!), + ), ], ), ), diff --git a/covas_mobile/lib/pages/EditSettings.dart b/covas_mobile/lib/pages/EditSettings.dart index 8ce10e3..e9c25ce 100644 --- a/covas_mobile/lib/pages/EditSettings.dart +++ b/covas_mobile/lib/pages/EditSettings.dart @@ -125,7 +125,7 @@ class _EditProfileState extends State child: TextButton( onPressed: () {}, child: Text( - 'Mettre à jour les paramètres', + 'Mettre à jour', style: TextStyle(color: Colors.white, fontSize: 25), ), ), diff --git a/covas_mobile/macos/Flutter/GeneratedPluginRegistrant.swift b/covas_mobile/macos/Flutter/GeneratedPluginRegistrant.swift index 32ef7bb..3f99c38 100644 --- a/covas_mobile/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/covas_mobile/macos/Flutter/GeneratedPluginRegistrant.swift @@ -10,6 +10,7 @@ import geolocator_apple import path_provider_foundation import shared_preferences_foundation import url_launcher_macos +import webview_flutter_wkwebview func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) @@ -17,4 +18,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) + WebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "WebViewFlutterPlugin")) } diff --git a/covas_mobile/pubspec.lock b/covas_mobile/pubspec.lock index 8440d75..86ac378 100644 --- a/covas_mobile/pubspec.lock +++ b/covas_mobile/pubspec.lock @@ -304,6 +304,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.3" + google_mobile_ads: + dependency: "direct main" + description: + name: google_mobile_ads + sha256: "0d4a3744b5e8ed1b8be6a1b452d309f811688855a497c6113fc4400f922db603" + url: "https://pub.dev" + source: hosted + version: "5.3.1" http: dependency: "direct main" description: @@ -877,6 +885,38 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + webview_flutter: + dependency: transitive + description: + name: webview_flutter + sha256: "889a0a678e7c793c308c68739996227c9661590605e70b1f6cf6b9a6634f7aec" + url: "https://pub.dev" + source: hosted + version: "4.10.0" + webview_flutter_android: + dependency: transitive + description: + name: webview_flutter_android + sha256: "512c26ccc5b8a571fd5d13ec994b7509f142ff6faf85835e243dde3538fdc713" + url: "https://pub.dev" + source: hosted + version: "4.3.2" + webview_flutter_platform_interface: + dependency: transitive + description: + name: webview_flutter_platform_interface + sha256: d937581d6e558908d7ae3dc1989c4f87b786891ab47bb9df7de548a151779d8d + url: "https://pub.dev" + source: hosted + version: "2.10.0" + webview_flutter_wkwebview: + dependency: transitive + description: + name: webview_flutter_wkwebview + sha256: "7310de7efa4e6df8b3d2ff14aef3f290bc00b43363f2d0028845e6de46507fc9" + url: "https://pub.dev" + source: hosted + version: "3.18.1" xdg_directories: dependency: transitive description: diff --git a/covas_mobile/pubspec.yaml b/covas_mobile/pubspec.yaml index 91f4711..a8ac907 100644 --- a/covas_mobile/pubspec.yaml +++ b/covas_mobile/pubspec.yaml @@ -50,6 +50,7 @@ dependencies: permission_handler: ^11.3.1 url_launcher: ^6.3.1 mapbox_gl: ^0.16.0 + google_mobile_ads: ^5.3.1 dev_dependencies: flutter_test: