This commit is contained in:
Valentin CZERYBA 2025-02-19 23:32:31 +01:00
parent 47c014cdda
commit 38e9908533
2 changed files with 40 additions and 4 deletions

View File

@ -11,7 +11,12 @@ import '../classes/alert.dart';
import '../variable/globals.dart' as globals; 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()); runApp(MyApp());
} }
@ -33,6 +38,8 @@ class AddProfile extends StatefulWidget {
} }
class _AddProfileState extends State<AddProfile> with ShowAlertDialog { class _AddProfileState extends State<AddProfile> with ShowAlertDialog {
BannerAd? _bannerAd;
TextEditingController inputUserName = TextEditingController(); TextEditingController inputUserName = TextEditingController();
TextEditingController inputName = TextEditingController(); TextEditingController inputName = TextEditingController();
@ -133,6 +140,11 @@ class _AddProfileState extends State<AddProfile> with ShowAlertDialog {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
AdHelper.createBannerAd(() => setState(() {})).then((ad) {
setState(() {
_bannerAd = ad;
});
});
} }
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
@ -154,6 +166,12 @@ class _AddProfileState extends State<AddProfile> with ShowAlertDialog {
child: SingleChildScrollView( child: SingleChildScrollView(
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
_bannerAd == null
? SizedBox.shrink()
: SizedBox(
height: _bannerAd!.size.height.toDouble(),
width: _bannerAd!.size.width.toDouble(),
child: AdWidget(ad: _bannerAd!)),
Padding( Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
left: 15.0, right: 15.0, top: 15, bottom: 0), left: 15.0, right: 15.0, top: 15, bottom: 0),

View File

@ -14,7 +14,12 @@ import 'dart:convert';
import '../variable/globals.dart' as globals; import '../variable/globals.dart' as globals;
import '../classes/MyDrawer.dart'; 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()); runApp(MyApp());
} }
@ -56,9 +61,18 @@ class DisplayPictureScreen extends StatefulWidget {
// A widget that displays the picture taken by the user. // A widget that displays the picture taken by the user.
class DisplayPictureScreenState extends State<DisplayPictureScreen> class DisplayPictureScreenState extends State<DisplayPictureScreen>
with ShowDescImageAdd, ShowAlertDialog, TickerProviderStateMixin { with ShowDescImageAdd, ShowAlertDialog, TickerProviderStateMixin {
BannerAd? _bannerAd;
late AnimationController controller; late AnimationController controller;
@override @override
void initState() { void initState() {
super.initState();
AdHelper.createBannerAd(() => setState(() {})).then((ad) {
setState(() {
_bannerAd = ad;
});
});
controller = AnimationController( controller = AnimationController(
/// [AnimationController]s can be created with `vsync: this` because of /// [AnimationController]s can be created with `vsync: this` because of
/// [TickerProviderStateMixin]. /// [TickerProviderStateMixin].
@ -68,7 +82,6 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
setState(() {}); setState(() {});
}); });
controller.repeat(reverse: false); controller.repeat(reverse: false);
super.initState();
_getEventInfosFromImage(); _getEventInfosFromImage();
} }
@ -160,12 +173,17 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
// The image is stored as a file on the device. Use the `Image.file` // The image is stored as a file on the device. Use the `Image.file`
// constructor with the given path to display the image. // constructor with the given path to display the image.
drawer: MyDrawer(), drawer: MyDrawer(),
body: Padding( body: Padding(
padding: const EdgeInsets.all(20.0), padding: const EdgeInsets.all(20.0),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[ children: <Widget>[
_bannerAd == null
? SizedBox.shrink()
: SizedBox(
height: _bannerAd!.size.height.toDouble(),
width: _bannerAd!.size.width.toDouble(),
child: AdWidget(ad: _bannerAd!)),
Text( Text(
'Analyse de l\'image en cours', 'Analyse de l\'image en cours',
style: Theme.of(context).textTheme.titleLarge, style: Theme.of(context).textTheme.titleLarge,