Skip to content

Commit

Permalink
fix/hot_restart_not_setting_method_call_handler (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
alhiwatan authored Jul 22, 2024
1 parent 8e003af commit 6061137
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
1 change: 1 addition & 0 deletions applovin_max/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Versions

## x.x.x
* Fix ad callbacks not firing after hot restart. https://github.com/AppLovin/AppLovin-MAX-Flutter/issues/229
* Fix `Null check operator used on a null value` warning in `MaxNativeAdView.dispose()`.
## 3.10.1
* Update `AppLovinMAX.initialize()` to return a `Future` on hot restart.
Expand Down
22 changes: 8 additions & 14 deletions applovin_max/lib/applovin_max.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ class AppLovinMAX {

/// Initializes the SDK.
///
/// This method must be called only once. Calling it multiple times may
/// cause the returned future to never complete.
///
/// For more information, see the [Initialize the SDK](https://developers.applovin.com/en/flutter/overview/integration).
///
/// See [this GitHub issue](https://github.com/AppLovin/AppLovin-MAX-Flutter/issues/210)
/// for more details on why calling `initialize` multiple times can lead to issues.
static Future<MaxConfiguration?> initialize(String sdkKey) async {
if (_hasInitializeInvoked) {
// Return a future object even when the actual value is not ready.
Expand All @@ -55,14 +49,6 @@ class AppLovinMAX {

_hasInitializeInvoked = true;

// isInitialized() returns true when Flutter is performing hot restart
bool isPlatformSDKInitialized = await isInitialized() ?? false;
if (isPlatformSDKInitialized) {
Map conf = await channel.invokeMethod('getConfiguration');
_initializeCompleter.complete(MaxConfiguration.fromJson(Map<String, dynamic>.from(conf)));
return _initializeCompleter.future;
}

channel.setMethodCallHandler((MethodCall call) async {
var method = call.method;
var arguments = call.arguments;
Expand Down Expand Up @@ -152,6 +138,14 @@ class AppLovinMAX {
}
});

// isInitialized() returns true when Flutter is performing hot restart
bool isPlatformSDKInitialized = await isInitialized() ?? false;
if (isPlatformSDKInitialized) {
Map conf = await channel.invokeMethod('getConfiguration');
_initializeCompleter.complete(MaxConfiguration.fromJson(Map<String, dynamic>.from(conf)));
return _initializeCompleter.future;
}

var conf = await channel.invokeMethod('initialize', {
'plugin_version': version,
'sdk_key': sdkKey,
Expand Down

0 comments on commit 6061137

Please sign in to comment.