|
| 1 | +import 'dart:async'; |
| 2 | + |
| 3 | +import 'package:core/core.dart'; |
| 4 | +import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_provider.dart'; |
| 5 | +import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_theme_style.dart'; |
| 6 | +import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/banner_ad.dart'; |
| 7 | +import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/interstitial_ad.dart'; |
| 8 | +import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/native_ad.dart'; |
| 9 | +import 'package:logging/logging.dart'; |
| 10 | +import 'package:uuid/uuid.dart'; |
| 11 | + |
| 12 | +/// {@template demo_ad_provider} |
| 13 | +/// A concrete implementation of [AdProvider] for the 'demo' ad platform. |
| 14 | +/// |
| 15 | +/// This provider simulates ad loading for the demo environment without |
| 16 | +/// making actual ad network calls. It returns placeholder ad objects |
| 17 | +/// for native, banner, and interstitial ads. |
| 18 | +/// {@endtemplate} |
| 19 | +class DemoAdProvider implements AdProvider { |
| 20 | + /// {@macro demo_ad_provider} |
| 21 | + DemoAdProvider({Logger? logger}) |
| 22 | + : _logger = logger ?? Logger('DemoAdProvider'); |
| 23 | + |
| 24 | + final Logger _logger; |
| 25 | + final Uuid _uuid = const Uuid(); |
| 26 | + |
| 27 | + @override |
| 28 | + Future<void> initialize() async { |
| 29 | + _logger.info('Demo Ad Provider initialized (no actual SDK to init).'); |
| 30 | + return Future.value(); |
| 31 | + } |
| 32 | + |
| 33 | + @override |
| 34 | + Future<NativeAd?> loadNativeAd({ |
| 35 | + required AdPlatformIdentifiers adPlatformIdentifiers, |
| 36 | + required String? adId, |
| 37 | + required AdThemeStyle adThemeStyle, |
| 38 | + HeadlineImageStyle? headlineImageStyle, |
| 39 | + }) async { |
| 40 | + _logger.info('Simulating native ad load for demo environment.'); |
| 41 | + // Simulate a delay for loading. |
| 42 | + await Future<void>.delayed(const Duration(milliseconds: 300)); |
| 43 | + |
| 44 | + return NativeAd( |
| 45 | + id: _uuid.v4(), |
| 46 | + provider: AdPlatformType.demo, |
| 47 | + adObject: Object(), // Placeholder object |
| 48 | + templateType: headlineImageStyle == HeadlineImageStyle.largeThumbnail |
| 49 | + ? NativeAdTemplateType.medium |
| 50 | + : NativeAdTemplateType.small, |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + @override |
| 55 | + Future<BannerAd?> loadBannerAd({ |
| 56 | + required AdPlatformIdentifiers adPlatformIdentifiers, |
| 57 | + required String? adId, |
| 58 | + required AdThemeStyle adThemeStyle, |
| 59 | + HeadlineImageStyle? headlineImageStyle, |
| 60 | + }) async { |
| 61 | + _logger.info('Simulating banner ad load for demo environment.'); |
| 62 | + // Simulate a delay for loading. |
| 63 | + await Future<void>.delayed(const Duration(milliseconds: 300)); |
| 64 | + |
| 65 | + return BannerAd( |
| 66 | + id: _uuid.v4(), |
| 67 | + provider: AdPlatformType.demo, |
| 68 | + adObject: Object(), // Placeholder object |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + @override |
| 73 | + Future<InterstitialAd?> loadInterstitialAd({ |
| 74 | + required AdPlatformIdentifiers adPlatformIdentifiers, |
| 75 | + required String? adId, |
| 76 | + required AdThemeStyle adThemeStyle, |
| 77 | + }) async { |
| 78 | + _logger.info('Simulating interstitial ad load for demo environment.'); |
| 79 | + // Simulate a delay for loading. |
| 80 | + await Future<void>.delayed(const Duration(milliseconds: 300)); |
| 81 | + |
| 82 | + return InterstitialAd( |
| 83 | + id: _uuid.v4(), |
| 84 | + provider: AdPlatformType.demo, |
| 85 | + adObject: Object(), // Placeholder object |
| 86 | + ); |
| 87 | + } |
| 88 | +} |
0 commit comments