mirror of
https://github.com/MoxiFoxi411/QuickSSH.git
synced 2026-11-08 19:34:55 +00:00
Added ads
This commit is contained in:
1 parent
eed999d2ab
commit
7c47298cd7
13 files changed
+258
-29
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MyBannerAd extends StatefulWidget {
|
||||
final bool isEnabled;
|
||||
const MyBannerAd({super.key, required this.isEnabled});
|
||||
|
||||
@override
|
||||
State<MyBannerAd> createState() => _MyBannerAdState();
|
||||
}
|
||||
|
||||
class _MyBannerAdState extends State<MyBannerAd> {
|
||||
BannerAd? _bannerAd;
|
||||
bool _isLoaded = false;
|
||||
bool _isInitializing = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.isEnabled) {
|
||||
_loadAd();
|
||||
}
|
||||
}
|
||||
|
||||
void _loadAd() async {
|
||||
_bannerAd = BannerAd(
|
||||
adUnitId: 'ca-app-pub-2626773788355001/7557216229',
|
||||
request: const AdRequest(),
|
||||
size: AdSize.banner,
|
||||
listener: BannerAdListener(
|
||||
onAdLoaded: (ad) => setState(() => _isLoaded = true),
|
||||
onAdFailedToLoad: (ad, error) {
|
||||
ad.dispose();
|
||||
print('Ad failed to load: $error');
|
||||
},
|
||||
),
|
||||
)..load();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_bannerAd?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!widget.isEnabled || !_isLoaded || _bannerAd == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
width: double.infinity,
|
||||
height: _bannerAd!.size.height.toDouble(),
|
||||
child: AdWidget(ad: _bannerAd!),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user