diff --git a/covas_mobile/lib/pages/AddProfile.dart b/covas_mobile/lib/pages/AddProfile.dart index 96d374b..f97fae4 100644 --- a/covas_mobile/lib/pages/AddProfile.dart +++ b/covas_mobile/lib/pages/AddProfile.dart @@ -11,7 +11,12 @@ import '../classes/alert.dart'; import '../variable/globals.dart' as globals; -void main() { +import '../classes/ad_helper.dart'; +import 'package:google_mobile_ads/google_mobile_ads.dart'; + +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + await MobileAds.instance.initialize(); runApp(MyApp()); } @@ -33,6 +38,8 @@ class AddProfile extends StatefulWidget { } class _AddProfileState extends State with ShowAlertDialog { + BannerAd? _bannerAd; + TextEditingController inputUserName = TextEditingController(); TextEditingController inputName = TextEditingController(); @@ -133,6 +140,11 @@ class _AddProfileState extends State with ShowAlertDialog { @override void initState() { super.initState(); + AdHelper.createBannerAd(() => setState(() {})).then((ad) { + setState(() { + _bannerAd = ad; + }); + }); } final _formKey = GlobalKey(); @@ -154,6 +166,12 @@ class _AddProfileState extends State with ShowAlertDialog { child: SingleChildScrollView( child: Column( children: [ + _bannerAd == null + ? SizedBox.shrink() + : SizedBox( + height: _bannerAd!.size.height.toDouble(), + width: _bannerAd!.size.width.toDouble(), + child: AdWidget(ad: _bannerAd!)), Padding( padding: const EdgeInsets.only( left: 15.0, right: 15.0, top: 15, bottom: 0), diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index 41c86fd..73711df 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -14,7 +14,12 @@ import 'dart:convert'; import '../variable/globals.dart' as globals; import '../classes/MyDrawer.dart'; -void main() { +import '../classes/ad_helper.dart'; +import 'package:google_mobile_ads/google_mobile_ads.dart'; + +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + await MobileAds.instance.initialize(); runApp(MyApp()); } @@ -56,9 +61,18 @@ class DisplayPictureScreen extends StatefulWidget { // A widget that displays the picture taken by the user. class DisplayPictureScreenState extends State with ShowDescImageAdd, ShowAlertDialog, TickerProviderStateMixin { + BannerAd? _bannerAd; + late AnimationController controller; @override void initState() { + super.initState(); + AdHelper.createBannerAd(() => setState(() {})).then((ad) { + setState(() { + _bannerAd = ad; + }); + }); + controller = AnimationController( /// [AnimationController]s can be created with `vsync: this` because of /// [TickerProviderStateMixin]. @@ -68,7 +82,6 @@ class DisplayPictureScreenState extends State setState(() {}); }); controller.repeat(reverse: false); - super.initState(); _getEventInfosFromImage(); } @@ -160,12 +173,17 @@ class DisplayPictureScreenState extends State // The image is stored as a file on the device. Use the `Image.file` // constructor with the given path to display the image. drawer: MyDrawer(), - body: Padding( padding: const EdgeInsets.all(20.0), child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + _bannerAd == null + ? SizedBox.shrink() + : SizedBox( + height: _bannerAd!.size.height.toDouble(), + width: _bannerAd!.size.width.toDouble(), + child: AdWidget(ad: _bannerAd!)), Text( 'Analyse de l\'image en cours', style: Theme.of(context).textTheme.titleLarge,