add macOS support for ad loading and improve timestamp handling
Some checks failed
Build Android App / build (push) Failing after 49s
Some checks failed
Build Android App / build (push) Failing after 49s
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import "dart:io" show Platform;
|
||||
import "package:flutter/foundation.dart" show kIsWeb;
|
||||
import "package:flutter/widgets.dart";
|
||||
import "package:shadcn_flutter/shadcn_flutter.dart";
|
||||
@@ -15,11 +16,19 @@ class AdBanner extends StatefulWidget {
|
||||
class _AdBannerState extends State<AdBanner> {
|
||||
late AdService _adService;
|
||||
bool _isLoading = true;
|
||||
bool _isMacOS = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initializeAds();
|
||||
|
||||
// check if running on macOS
|
||||
if (!kIsWeb && Platform.isMacOS) {
|
||||
_isMacOS = true;
|
||||
_isLoading = false;
|
||||
} else {
|
||||
_initializeAds();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _initializeAds() async {
|
||||
@@ -46,12 +55,42 @@ class _AdBannerState extends State<AdBanner> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_adService.dispose();
|
||||
if (!_isMacOS) {
|
||||
_adService.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
// Check if we're on mobile (iOS/Android)
|
||||
bool isMobile = !kIsWeb && !_isMacOS && (Platform.isIOS || Platform.isAndroid);
|
||||
|
||||
// Show placeholder only on macOS and web when ads fail to load
|
||||
// On mobile, we want real ads or nothing
|
||||
if (_isMacOS || (!isMobile && !_isLoading && !_adService.isLoaded)) {
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: 80,
|
||||
),
|
||||
child: OutlinedContainer(
|
||||
child: Center(
|
||||
child: Text(
|
||||
"ADVERTISEMENT SPACE",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.mutedForeground,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
).withPadding(
|
||||
horizontal: 8
|
||||
);
|
||||
}
|
||||
|
||||
if (_isLoading) {
|
||||
return SizedBox(
|
||||
height: 50,
|
||||
@@ -65,11 +104,6 @@ class _AdBannerState extends State<AdBanner> {
|
||||
);
|
||||
}
|
||||
|
||||
if (!_adService.isLoaded) {
|
||||
// Ad failed to load, show nothing
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
|
||||
return _adService.getBannerWidget();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user