@@ -7,12 +7,17 @@ import 'package:data_api/data_api.dart';
77import 'package:data_client/data_client.dart' ;
88import 'package:data_inmemory/data_inmemory.dart' ;
99import 'package:data_repository/data_repository.dart' ;
10+ import 'package:flutter/foundation.dart' show kIsWeb; // Import kIsWeb
1011import 'package:flutter/material.dart' ;
1112import 'package:flutter_bloc/flutter_bloc.dart' ;
1213import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_provider.dart' ;
1314import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_service.dart' ;
14- import 'package:flutter_news_app_mobile_client_full_source_code/ads/admob_ad_provider.dart' ;
15- import 'package:flutter_news_app_mobile_client_full_source_code/ads/demo_ad_provider.dart' ; // Added DemoAdProvider
15+ // Conditional import for AdMobAdProvider
16+ // This ensures the AdMob package is only imported when not on the web,
17+ // preventing potential issues or unnecessary logs on web platforms.
18+ import 'package:flutter_news_app_mobile_client_full_source_code/ads/admob_ad_provider.dart'
19+ if (dart.library.io) 'package:flutter_news_app_mobile_client_full_source_code/ads/admob_ad_provider.dart' ;
20+ import 'package:flutter_news_app_mobile_client_full_source_code/ads/demo_ad_provider.dart' ;
1621import 'package:flutter_news_app_mobile_client_full_source_code/ads/local_ad_provider.dart' ;
1722import 'package:flutter_news_app_mobile_client_full_source_code/app/app.dart' ;
1823import 'package:flutter_news_app_mobile_client_full_source_code/app/config/config.dart'
@@ -90,17 +95,19 @@ Future<Widget> bootstrap(
9095 // Conditionally instantiate ad providers based on the application environment.
9196 // This ensures that only the relevant ad providers are available for the
9297 // current environment, preventing unintended usage.
93- if (appConfig.environment == app_config.AppEnvironment .demo) {
98+ if (appConfig.environment == app_config.AppEnvironment .demo || kIsWeb ) {
9499 final demoAdProvider = DemoAdProvider (logger: logger);
95100 adProviders = {
96- // In the demo environment, all ad platform types map to the DemoAdProvider.
97- // This simulates ad behavior without actual network calls.
101+ // In the demo environment or on the web, all ad platform types map to
102+ // the DemoAdProvider. This simulates ad behavior without actual network
103+ // calls and avoids issues with platform-specific ad SDKs on unsupported
104+ // platforms (e.g., AdMob on web).
98105 AdPlatformType .admob: demoAdProvider,
99106 AdPlatformType .local: demoAdProvider,
100107 AdPlatformType .demo: demoAdProvider,
101108 };
102109 } else {
103- // For development and production environments, use real ad providers.
110+ // For development and production environments (non-web) , use real ad providers.
104111 adProviders = {
105112 // AdMob provider for Google Mobile Ads.
106113 AdPlatformType .admob: AdMobAdProvider (logger: logger),
@@ -117,7 +124,7 @@ Future<Widget> bootstrap(
117124 ),
118125 logger: logger,
119126 ),
120- // The demo ad platform is not available in non-demo environments.
127+ // The demo ad platform is not available in non-demo/non-web environments.
121128 // If AdService attempts to access it, it will receive null, which is
122129 // handled by AdService's internal logic (logging a warning).
123130 };
0 commit comments