initialize method

Future<Map<String, dynamic>?> initialize({
  1. String? appId,
})

Initializes the Google Mobile Ads SDK.

appId - Optional App ID. If not provided, the SDK will use the App ID configured in the platform-specific configuration files.

Returns a map containing initialization status and adapter information. Returns null if initialization fails.

Example:

final result = await ads.initialize(appId: 'ca-app-pub-xxxxx');
if (result?['isReady'] == true) {
  print('AdMob initialized successfully');
}

Implementation

Future<Map<String, dynamic>?> initialize({String? appId}) async {
  try {
    final result = await _channel.invokeMethod<Map<dynamic, dynamic>>(
      'initialize',
      {'appId': appId},
    );
    return result?.cast<String, dynamic>();
  } catch (e) {
    debugPrint('Error initializing AdMob: $e');
    return null;
  }
}